Advertisement
Nathan423

Untitled

Jun 28th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. local function toggleLight(name)
  2. for i=1, #buttons do
  3. if buttons[i][1] == name then
  4. if buttons[i][2] then
  5. color = buttons[i][2]
  6. bundleAPI.toggle(bundleLoc, color)
  7. end
  8. end
  9. end
  10. end
  11.  
  12. os.loadAPI("touchPoint")
  13. os.loadAPI("bundleAPI")
  14.  
  15. if monitorLoc == nil then
  16. error("No monitor side has been defined")
  17. os.exit()
  18. end
  19. local monitor = peripheral.wrap(monitorLoc)
  20. if not peripheral.getType(monitorLoc) == "monitor" then
  21. error("the monitor isn't on the specified side")
  22. os.exit()
  23. end
  24.  
  25. local w, h = monitor.getSize()
  26. print([[Size (w): ]]..w)
  27. print([[Size (h): ]]..h)
  28. local columnW = 12
  29. local rowW = 2
  30.  
  31. local currentColumn = 2
  32. local currentRow = 2
  33. local t = touchPoint.new(monitorLoc)
  34.  
  35. for i=1, #buttons do
  36. print([[Button: ]]..buttons[i][1]..[[ Type: ]]..tostring(buttons[i][3]))
  37. local Inactive
  38. local Active
  39. if buttons[i][3] then
  40. Inactive = colors.lime
  41. Active = colors.red
  42. bundleAPI.toggle(bundleLoc, buttons[i][2])
  43. else
  44. Inactive = colors.red
  45. Active = colors.lime
  46. end
  47. t:add(buttons[i][1], nil, currentColumn, currentRow, currentColumn + columnW, currentRow + rowW, Inactive, Active)
  48. if currentColumn == 2 then
  49. currentColumn = 16
  50. else
  51. currentColumn = 2
  52. currentRow = currentRow + rowW + 2
  53. end
  54. end
  55. t:draw()
  56.  
  57. while true do
  58. local event, p1 = t:handleEvents(os.pullEvent())
  59. if event == "button_click" then
  60. toggleLight(p1)
  61. t:toggleButton(p1)
  62. print([[Button ]] ..p1.. [[ was pushed]])
  63. end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement