Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p = peripheral.wrap("back")
- rednet.open("right")
- p.setTextScale(1.5)
- p.setBackgroundColor(colors.black)
- button={}
- function split(str, delim, maxNb)
- if string.find(str, delim) == nil then
- return { str }
- end
- if maxNb == nil or maxNb < 1 then
- maxNb = 0
- end
- local result = {}
- local pat = "(.-)" ..delim.. "()"
- local nb = 0
- local lastPos
- for part, pos in string.gmatch(str, pat) do
- nb = nb + 1
- result[nb] = part
- if nb == maxNb then
- break
- end
- end
- return result
- end
- function setTable(name, func, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- function cobble()
- p.clear()
- sleep(5)
- setTable("1", send, 14, 21, 5, 9)
- screenNum()
- sleep(0.5)
- function2()
- end
- function send()
- print(thing)
- run = 1
- end
- function fillNum(text, color, bData)
- p.setBackgroundColor(colors.lime)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- p.setCursorPos(bData["xmin"], bData["ymin"])
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- p.write(text)
- else
- p.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- p.write(" ")
- end
- end
- end
- p.setBackgroundColor(colors.black)
- end
- function screenNum()
- local currColor
- for name,data in pairs(button) do
- currColor = colors.lime
- fillNum(name, currColor, data)
- end
- run = 0
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if y >=data["ymin"] and y <= data["ymax"] then
- if x >=data["xmin"] and x <= data["xmax"] then
- data["func"]()
- end
- end
- end
- end
- function fill(text, color, bData)
- p.setCursorPos(bData["xmin"], bData["ymin"])
- p.write(text)
- end
- function screen()
- for name,data in pairs(button) do
- fill(name, currColor, data)
- end
- end
- function1 = function()
- line = 2
- item = 89
- p.clear()
- for i=1, 10 do
- rednet.send(item, "update")
- id, message = rednet.receive(0.5)
- if message == nil then
- return
- else
- length = string.len(message) + 3
- setTable(message, cobble, 3, length, line, line)
- mess = {}
- mess = split(message, ":")
- thing = tostring(mess[1])
- line = line + 1
- item = item + 1
- screen()
- end
- sleep(10)
- end
- end
- function2 = function()
- event, side, x, y = os.pullEvent("monitor_touch")
- print(x.." "..y)
- checkxy(x,y)
- end
- while true do
- parallel.waitForAny(function2,function1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement