Advertisement
MTM123

toggler

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