Molinko

redstonebutton

Aug 5th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. local args = {...}
  2. if not args[1] then error("Usage: <programName> <redstone output side>") end
  3. if not fs.exists("buttonObjAPI") then
  4.     shell.run("pastebin","get","UwAgPsje","buttonObjAPI")
  5. end
  6. local mon
  7. for _,side in pairs(rs.getSides()) do
  8.     if peripheral.getType(side) == "monitor" and term.isColor() == true then
  9.         mon = peripheral.wrap(side)
  10.         break
  11.     end
  12. end
  13. if not mon then error("no monitor attached. monitor must be advanced!!!") end
  14. mon.setTextScale(tonumber(args[2]) or .5)
  15. dofile("buttonObjAPI")
  16. term.clear()
  17. term.setCursorPos(1,1)
  18. term.write("press enter to quit..")
  19. term.redirect(mon)
  20. local state = false
  21. local rsOut = tostring(args[1])
  22. b1 = setButton({name="On / Off",xStart=2,yStart=2,xPadding=1,yPadding=2,visible=true,})
  23.  
  24. while true do
  25.     b1.draw()
  26.     local e = {os.pullEvent()}
  27.     if e[1] == "monitor_touch" then
  28.         if b1.isWithin(e[3],e[4]) then
  29.             state = not state
  30.             b1.setState(state)
  31.         end
  32.     elseif e[1] == "key" and e[2] == keys.enter then
  33.         break
  34.     end
  35.     rs.setOutput(rsOut,state)
  36. end
  37. term.restore()
Advertisement
Add Comment
Please, Sign In to add comment