Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables
- monitorSide = "right"
- redstoneSide = "left"
- mon = peripheral.wrap(monitorSide)
- tButtons = {
- { text = "Redstone ON", x = 1, y = 1, col = colours.lime },
- { text = "Redstone 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 -- verifies the X position
- and my == v.y then -- Y position
- return true, v.text -- valid click so it returns true and what text was clicked
- end
- end
- return false, nil -- If the button is invalid, return false and nil
- end
- local function printTable( tab ) -- Function to print any table
- print("Printing the options for table onto the monitor...")
- for _, v in pairs( tab ) do
- term.setCursorPos( v.x, v.y )
- term.setBackgroundColour( v.col )
- mon.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 ) -- calls the function to check if it's a valid click
- if bValidClick then -- if it's a valid click
- if sText == "Redstone ON" then -- if the text returned is 'Redstone ON'
- redstone.setOutput( "back", true )
- print( "Redstone signal has been turned ON" )
- elseif sText == "Redstone OFF" -- if the text returned is 'Redstone OFF'
- redstone.setOutput( "back", false )
- print( "Redstone signal has been turned OFF" )
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment