Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- t = {
- {text = "Button 1", x = 1, y = 1, txtCol = colours.red, bgCol = colours.lime},
- {text = "Button 2", x = 1, y = 2, txtCol = colours.red, bgCol = colours.lime},
- {text = "Button 3", x = 1, y = 3, txtCol = colours.red, bgCol = colours.lime}
- }
- mon = peripherial.wrap("side")
- function writeButtons(_table)
- for i, v in pairs(_table) do
- term.setCursorPos(v.x, v.y)
- term.setTextColour(v.txtCol)
- term.setBackgroundColour(v.bgCol)
- write(v.text)
- end
- end
- function isValidClick(_table, mx, my)
- for i, v in pairs(_table) do
- if mx >= v.x and mx <= (v.x + #v.text) and my == v.y then
- return true, v.text
- end
- end
- return false, nil
- end
- writeButtons(t)
- while true do
- _, but, x, y = os.pullEvent("monitor_touch")
- bClick, option = isValidClick(t, x, y)
- if bClick then
- -- Yes, it's a valid click. Now let's do something with the returned text 'option'
- if option == "Button 1" then -- button 1...
- elseif option == "Button 2" then
- elseif option == "Button 3" then
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement