Advertisement
Gomo

CC Elevator Program

Jan 29th, 2015
1,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. local thisTerminalsFloor = 1
  2.  
  3. rs.setOutput("left", false)
  4. rs.setOutput("right", false)
  5.  
  6. while rs.getInput("left") or rs.getInput("right") do
  7.         print("Appears lelevator is already in use. Please wait...")
  8.         os.pullEvent("redstone")
  9.         sleep(1)
  10. end
  11.  
  12. local function findElevator()
  13.         if rs.getInput("top") then return 1 end     -- Elevator at floor 1.
  14.         if rs.getInput("back") then return 2 end    -- Elevator at floor 2.
  15.         if rs.getInput("bottom") then return 3 end  -- Elevator at floor 3.
  16.         return false
  17. end
  18.  
  19. local function moveElevator(elevatorFloor, destFloor)
  20.         if elevatorFloor ~= destFloor then
  21.                 print("Moving from floor "..tostring(elevatorFloor).." to floor "..tostring(destFloor).."...")
  22.  
  23.                 local signalSide = destFloor < elevatorFloor and "right" or "left"
  24.  
  25.                 repeat
  26.                         rs.setOutput(signalSide, true)
  27.                         os.pullEvent("redstone")
  28.                         rs.setOutput(signalSide, false)
  29.                 until findElevator() == destFloor
  30.         end
  31. end
  32.  
  33. local input
  34. while (not input) or input < 1 or input > 3 do
  35.         print("Enter target floor (1 - 3):")
  36.         input = tonumber(read())
  37. end
  38.  
  39. local currentFloor = findElevator()
  40. if not currentFloor then
  41.         print("Can't determine lift location.")
  42.         repeat
  43.                 rs.setOutput("right", true)
  44.                 os.pullEvent("redstone")
  45.                 print("Got possible lift signal; rechecking...")
  46.                 rs.setOutput("right", false)
  47.                 currentFloor = findElevator()
  48.         until currentFloor
  49. end
  50.  
  51. moveElevator(currentFloor, thisTerminalsFloor)
  52.  
  53. print("Please board.")
  54. sleep(5)
  55.  
  56. moveElevator(thisTerminalsFloor, input)
  57.  
  58. print("Operation complete.")
  59. sleep(2)
  60. os.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement