k_goos

Elevator V1

Jan 27th, 2022 (edited)
170
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local side = "left"
  2. local lastFloorDetection = 0
  3. local directionIsUp = true
  4.  
  5. local requestFloor = {false, false, false}
  6. local requestFloorColor = {colors.orange, colors.red, colors.blue}
  7. local detectFloorColor = {colors.lightBlue, colors.green, colors.black}
  8.  
  9. function EnableColor(color)
  10.     redstone.setBundledOutput(side, colors.combine(redstone.getBundledOutput(side), color))
  11. end
  12.  
  13. function DisableColor(color)
  14.     redstone.setBundledOutput(side, colors.subtract(redstone.getBundledOutput(side), color))
  15. end
  16.  
  17. function ElevatorUp()
  18.     print("Going up...")
  19.     DisableColor(colors.white)
  20. end
  21.  
  22. function ElevatorDown()
  23.     print("Going down...")
  24.     EnableColor(colors.white)
  25. end
  26.  
  27. function GotoFloor(index)
  28.  
  29. end
  30.  
  31. function CheckFloors()
  32.     for i, v in ipairs(requestFloorColor) do
  33.         if rs.testBundledInput(side, v) then
  34.             print("Request for floor " .. i)
  35.             return i
  36.         end
  37.     end
  38. end
  39.  
  40. function DetectFloor()
  41.     for i, v in ipairs(detectFloorColor) do
  42.         if rs.testBundledInput(side, v) then
  43.             print("Detected elevator at floor " .. i)
  44.             return i
  45.         end
  46.     end
  47. end
  48.  
  49. function Calibrate()
  50.     print("Calibration in progress...")
  51.     ElevatorUp()
  52. end
  53.  
  54. function RedstoneDetected()
  55.     currentFloor = DetectFloor()
  56.  
  57.     if currentFloor ~= 0 then
  58.         lastFloorDetection = currentFloor
  59.     else
  60.         floorIndex = CheckFloors()
  61.         GotoFloor(floorIndex)
  62.     end
  63. end
  64.  
  65. function SimpleElevator()
  66.     if rs.testBundledInput(side, colors.white) then
  67.         return
  68.     end
  69.  
  70.     print("Redstone input detected...")
  71.  
  72.     if directionIsUp then
  73.         ElevatorDown()
  74.         directionIsUp = false
  75.     else
  76.         ElevatorUp()
  77.         directionIsUp = true
  78.     end
  79. end
  80.  
  81. print( "Press E to quit." )
  82. --Main code
  83. while true do
  84.     local e = os.pullEvent()
  85.  
  86.     if e == "key" then
  87.         print( "You pressed [E]. Exiting program..." )
  88.         break
  89.     end
  90.  
  91.     if e == "redstone" then
  92.         SimpleElevator()
  93.     end
  94. end
RAW Paste Data Copied