Advertisement
SenpaiJody

Elevator Client

Oct 31st, 2022 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. rednet.open("back")
  2. local controllerID = 14
  3. os.loadAPI("button")
  4.  
  5. local levels = {}
  6.  
  7. function setControllerID(id)
  8.     controllerID = id
  9.     end
  10. function addLevel(name)
  11.     table.insert(levels,name)
  12.     end
  13.  
  14. local function fillTable()
  15.     local i = 1
  16.     rednet.send(controllerID,"getCurrentLevel","BUD_ELEVATOR")
  17.     local num, msg = rednet.receive("BUD_ELEVATOR")
  18.     local currentLevel = tonumber(msg)
  19.     for k,v in pairs(levels) do
  20.         local j = i
  21.         button.setTable(v,
  22.             function()
  23.                 button.flash(v)
  24.                 rednet.send(controllerID, "move`"..j, "BUD_ELEVATOR")
  25.                 end
  26.             , 10, 40, i*4-2, i*4)
  27.         if i == currentLevel then
  28.             button.toggleButton(v)
  29.             end
  30.         i = i + 1
  31.         end
  32.     button.screen()
  33.     end
  34.  
  35. function heading(str)
  36.     button.heading(str)
  37.     end
  38.  
  39. local function getClick()
  40.    event,side,x,y = os.pullEvent("mouse_click")
  41.    button.checkxy(x,y)
  42. end
  43.  
  44.  
  45. function start()
  46.     fillTable()
  47.     while true do
  48.         getClick()
  49.         end
  50.     end
  51.  
  52. --term.clear()
  53. --heading("---- Elevator ----")
  54. --addLevel("Lobby")
  55. --addLevel("Basement")
  56. --start()
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement