Advertisement
Guest User

Light

a guest
Dec 13th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. tButtons = {
  2. { text = "ON", x = 1, y = 1, col = colours.lime },
  3. { text = "OFF", x = 1, y = 1, col = colours.red }
  4. }
  5.  
  6. local function isValidClick( tab, mx, my )
  7. for _, v in pairs( tab ) do
  8. if mx >= v.x and mx <= v.x + #v.text - 1
  9. and my == v.y then
  10. return true, v.text
  11. end
  12. end
  13. return false, nil
  14. end
  15.  
  16. local function printTable( tab )
  17. for _, v in pairs( tab ) do
  18. term.setCursorPos( v.x, v.y )
  19. term.setBackgroundColour( v.col )
  20. write( v.text )
  21. end
  22. end
  23.  
  24. printTable( tButtons )
  25.  
  26. while true do
  27. local event, but, X, Y = os.pullEvent()
  28. if event == "monitor_touch" then
  29. bValidClick, sText = isValidClick( tButtons, X, Y )
  30. if bValidClick then
  31. if sText == "ON" then
  32. redstone.setOutput( "back", true )
  33. elseif sText == "OFF"
  34. redstone.setOutput( "back", false )
  35. end
  36. end
  37. end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement