Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tButtons = {
- { text = "ON", x = 1, y = 1, col = colours.lime },
- { text = "OFF", x = 1, y = 1, col = colours.red }
- }
- local function isValidClick( tab, mx, my )
- for _, v in pairs( tab ) do
- if mx >= v.x and mx <= v.x + #v.text - 1
- and my == v.y then
- return true, v.text
- end
- end
- return false, nil
- end
- local function printTable( tab )
- for _, v in pairs( tab ) do
- term.setCursorPos( v.x, v.y )
- term.setBackgroundColour( v.col )
- write( v.text )
- end
- end
- printTable( tButtons )
- while true do
- local event, but, X, Y = os.pullEvent()
- if event == "monitor_touch" then
- bValidClick, sText = isValidClick( tButtons, X, Y )
- if bValidClick then
- if sText == "ON" then
- redstone.setOutput( "back", true )
- elseif sText == "OFF"
- redstone.setOutput( "back", false )
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement