daily pastebin goal
58%
SHARE
TWEET

Computercraft Elevator

awesome8digger Jul 12th, 2018 (edited) 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function UserInput()
  2.     term.clear()
  3.     term.setCursorPos(1,1)
  4.     print("Enter The Desired Floor")
  5.     local input = read()
  6.     if input == "1" then
  7.         calculateFloors(1)
  8.         UserInput()
  9.     elseif input == "2" then
  10.         calculateFloors(2)
  11.         UserInput()
  12.     elseif input == "3" then
  13.         calculateFloors(3)
  14.         UserInput()
  15.     elseif input == "4" then
  16.         calculateFloors(4)
  17.         UserInput()
  18.     elseif input == "5" then
  19.         calculateFloors(5)
  20.         UserInput()
  21.     elseif input == "6" then
  22.         calculateFloors(6)
  23.         UserInput()
  24.     elseif input == "DebugUp" then
  25.         Up()
  26.         UserInput()
  27.     elseif input == "DebugDown" then
  28.         Down()
  29.         UserInput()
  30.     end
  31. end
  32.  
  33. function calculateFloors(desiredFloor)
  34.     local floorDifference = getCurrentFloor() - desiredFloor
  35.     if floorDifference == 0 then
  36.         UserInput()
  37.     end
  38.     if floorDifference < 0 then
  39.         for d = 1, math.abs(floorDifference) do
  40.             DownFloor()
  41.         end
  42.     else
  43.         for d = 1, floorDifference do
  44.             UpFloor()
  45.         end
  46.     end
  47. end
  48.  
  49. function getCurrentFloor()
  50.     local signal = redstone.getAnalogInput("back")
  51.     if signal == 0 then
  52.         print("Not Currently On A Floor. Type DebugUp Or DebugDown To Move Up Or Down One Block")
  53.         os.sleep(5)
  54.         UserInput()
  55.     else
  56.         return signal
  57.     end
  58. end
  59.  
  60. function UpFloor()
  61.     for f = 1, 10 do
  62.         Up()
  63.     end
  64. end
  65.  
  66. function DownFloor()
  67.     for f = 1, 10 do
  68.         Down()
  69.     end
  70. end
  71.  
  72. function Up()
  73.     redstone.setBundledOutput("left", 1)
  74.     os.sleep(0.8)
  75.     redstone.setBundledOutput("left", 0)
  76. end
  77.  
  78. function Down()
  79.     redstone.setBundledOutput("left", 2)
  80.     os.sleep(0.8)
  81.     redstone.setBundledOutput("left", 0)
  82. end
  83.  
  84. UserInput()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top