Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- t = {
- { label = "Button1", x = 1, y = 1, tCol = colors.lime, bgCol = colors.red },
- { label = "Button2", x = 1, y = 2, tCol = colors.lime, bgCol = colors.red },
- { label = "Button3", x = 1, y = 3, tCol = colors.lime, bgCol = colors.red },
- { label = "Button4", x = 1, y = 4, tCol = colors.lime, bgCol = colors.red }
- }
- m = peripheral.wrap("left")
- rednet.open("right")
- m.setBackgroundColor(colors.black)
- m.clear()
- --function function1()
- --print("function 1 running!")
- --sleep(5)
- --end
- --function function2()
- --print("function 2 running!")
- --sleep(5)
- --end
- --function function3()
- --print("function 3 running!")
- --sleep(5)
- --end
- --function function4()
- --print("function 4 running!")
- --sleep(5)
- --end
- function createButtons(_table)
- for i, v in pairs(_table) do
- m.setCursorPos(v.x, v.y)
- m.setTextColor(v.tCol)
- m.setBackgroundColor(v.bgCol)
- m.write(v.label)
- end
- end
- function isButtonClicked(_table, mx, my)
- for i, v in pairs(_table) do
- if mx >= v.x and mx <= (v.x + #v.label) and my == v.y then
- return true, v.label
- end
- end
- return false, nil
- end
- createButtons(t)
- while true do
- e, s, x, y = os.pullEvent("monitor_touch")
- isClicked, option = isButtonClicked(t, x, y)
- if isClicked then
- if option == "Button1" then
- --function1()
- rednet.broadcast(option)
- elseif option == "Button2" then
- --function2()
- rednet.broadcast(option)
- elseif option == "Button3" then
- -- function3()
- rednet.broadcast(option)
- elseif option == "Button4" then
- -- function4()
- rednet.broadcast(option)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement