ThatGravyBoat

State Controller

Feb 1st, 2022 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. --State Controller
  2. --Consts--
  3. local floorChanger = 7
  4. local door1 = 8
  5. local door2 = 10
  6. peripheral.find("modem", rednet.open)
  7.  
  8. local floor = 0
  9. local running = false
  10.  
  11. string.startswith = function(self, str)
  12. return self:find('^' .. str) ~= nil
  13. end
  14.  
  15. while true do
  16. local id, message = rednet.receive()
  17.  
  18. if message == "elevatorRunning" then
  19. running = not running
  20. elseif message:startswith("changeFloor") then
  21. local requestedFloor0 = string.sub(message, 12, 13) == "0"
  22. if not running and ((requestedFloor0 and floor == 1) or (not requestedFloor0 and floor == 0)) then
  23. if floor == 0 then
  24. floor = 1
  25. rednet.send(door1, "closeDoor0")
  26. rednet.send(door2, "closeDoor0")
  27. else
  28. floor = 0
  29. rednet.send(door1, "closeDoor1")
  30. rednet.send(door2, "closeDoor1")
  31. end
  32. rednet.send(floorChanger, "flip")
  33. end
  34. end
  35. end
Advertisement
Add Comment
Please, Sign In to add comment