xuma202

[CCPDA] Redstone controller

Apr 5th, 2012
219
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function updateOutputs()
  2.     redstone.setOutput("back", out[1])
  3.     redstone.setOutput("left", out[2])
  4.     redstone.setOutput("right", out[3])
  5.     redstone.setOutput("front", out[4])
  6. end
  7.  
  8. function boolToStr(b)
  9.     if b == true then
  10.         return "true"
  11.     else
  12.         return "false"
  13.     end
  14. end
  15.  
  16. gui = peripheral.wrap("top")
  17. gui.registerAsEventListener()
  18.  
  19. out = {false, false, false, false}
  20. button = {0,0,0,0}
  21.  
  22. updateOutputs()
  23.  
  24. gui.createGui()
  25.  
  26.  
  27. while true do
  28.   a = os.pullEvent()
  29.   if a == "PDA_Use" then
  30.     gui.displayGui()
  31.     gui.addCenText("Redstone Output Control", math.floor(gui.getWidth() / 2), 10, -1)
  32.     button[1] = gui.addButton(1, math.floor(gui.getWidth() / 4), 30, math.floor(gui.getWidth() / 2), 20, "")
  33.     button[2] = gui.addButton(2, math.floor(gui.getWidth() / 4), 60, math.floor(gui.getWidth() / 2), 20, "")
  34.     button[3] = gui.addButton(3, math.floor(gui.getWidth() / 4), 90, math.floor(gui.getWidth() / 2), 20, "")
  35.     button[4] = gui.addButton(4, math.floor(gui.getWidth() / 4), 120, math.floor(gui.getWidth() / 2), 20, "")
  36.    
  37.     gui.setButtonText(button[1], "Back: "..boolToStr(out[1]))
  38.     gui.setButtonText(button[2], "Left: "..boolToStr(out[2]))
  39.     gui.setButtonText(button[3], "Right: "..boolToStr(out[3]))
  40.     gui.setButtonText(button[4], "Front: "..boolToStr(out[4]))
  41.    
  42.     while gui.isGuiVisible() do
  43.         a, b = os.pullEvent()
  44.         if a == "GUI_ButtonClick" then
  45.             out[b] = not out[b]
  46.             updateOutputs()
  47.            
  48.             gui.setButtonText(button[1], "Back: "..boolToStr(out[1]))
  49.             gui.setButtonText(button[2], "Left: "..boolToStr(out[2]))
  50.             gui.setButtonText(button[3], "Right: "..boolToStr(out[3]))
  51.             gui.setButtonText(button[4], "Front: "..boolToStr(out[4]))
  52.         end
  53.     end
  54.   end
  55. end
RAW Paste Data