Advertisement
MTM123

toggler

Oct 29th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. local component = require("component")
  2. local gpu = component.gpu
  3. local redstone = component.redstone
  4. local sides = require("sides")
  5. gpu.setResolution(80,25)
  6. local gui = require("gui")
  7. local event = require("event")
  8.  
  9. gui.checkVersion(2,5)
  10.  
  11. local prgName = "Toggler"
  12. local version = "v1.0"
  13.  
  14. local state = false
  15. local function onoff_btn_callback(guiID, buttonID)
  16. if state == false then
  17. state = true
  18. redstone.setOutput(sides.right, 15)
  19. updateLabel(true)
  20. else
  21. state = false
  22. redstone.setOutput(sides.right, 0)
  23. updateLabel(false)
  24. end
  25. end
  26.  
  27. local function exitButtonCallback(guiID, id)
  28. local result = gui.getYesNo("", "Do you really want to exit?", "")
  29. if result == true then
  30. gui.exit()
  31. end
  32. gui.displayGui(mainGui)
  33. refresh()
  34. end
  35. -- End: Callbacks
  36.  
  37. -- Begin: Menu definitions
  38. mainGui = gui.newGui(1, 2, 79, 23, true)
  39. on_off = gui.newButton(mainGui, 35, 12, "On/Off", onoff_btn_callback)
  40. label_0 = gui.newLabel(mainGui, 33, 10, "Currently on", 0xff00, 0x0, 7)
  41. exitButton = gui.newButton(mainGui, 73, 23, "exit", exitButtonCallback)
  42. -- End: Menu definitions
  43.  
  44. local function updateLabel(state)
  45. if state == true then
  46. gui.setText(mainGui, label_0, "Currently on", true)
  47. gui.setBackground(mainGui, label_0, 0x00ff00)
  48. else
  49. gui.setText(mainGui, label_0, "Currently off", true)
  50. gui.setBackground(mainGui, label_0, 0x0000ff)
  51. end
  52. end
  53.  
  54. gui.clearScreen()
  55. gui.setTop("noname")
  56. gui.setBottom("Made with Visual Gui v0.1a and Gui library v2.5")
  57.  
  58. -- Main loop
  59. while true do
  60. gui.runGui(mainGui)
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement