SteamyPotatoes

Untitled

Jun 1st, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. --Variables
  2. monitorSide = "right"
  3. redstoneSide = "left"
  4. mon = peripheral.wrap(monitorSide)
  5.  
  6. tButtons = {
  7. { text = "Redstone ON", x = 1, y = 1, col = colours.lime },
  8. { text = "Redstone OFF", x = 1, y = 1, col = colours.red }
  9. }
  10.  
  11. local function isValidClick( tab, mx, my )
  12. for _, v in pairs( tab ) do
  13. if mx >= v.x and mx <= v.x + #v.text - 1 -- verifies the X position
  14. and my == v.y then -- Y position
  15. return true, v.text -- valid click so it returns true and what text was clicked
  16. end
  17. end
  18. return false, nil -- If the button is invalid, return false and nil
  19. end
  20.  
  21. local function printTable( tab ) -- Function to print any table
  22. print("Printing the options for table onto the monitor...")
  23. for _, v in pairs( tab ) do
  24. term.setCursorPos( v.x, v.y )
  25. term.setBackgroundColour( v.col )
  26. mon.write( v.text )
  27. end
  28. end
  29.  
  30. printTable( tButtons )
  31.  
  32. while true do
  33. local event, but, X, Y = os.pullEvent()
  34. if event == "monitor_touch" then
  35. bValidClick, sText = isValidClick( tButtons, X, Y ) -- calls the function to check if it's a valid click
  36. if bValidClick then -- if it's a valid click
  37. if sText == "Redstone ON" then -- if the text returned is 'Redstone ON'
  38. redstone.setOutput( "back", true )
  39. print( "Redstone signal has been turned ON" )
  40. elseif sText == "Redstone OFF" -- if the text returned is 'Redstone OFF'
  41. redstone.setOutput( "back", false )
  42. print( "Redstone signal has been turned OFF" )
  43. end
  44. end
  45. end
  46. end
Add Comment
Please, Sign In to add comment