Advertisement
Swimy

ChronosLabs: DoorUtils

Feb 1st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. local sleepTime = .1
  2. local open = false
  3. local modemPos = 'top'
  4. local bundleCableSide = 'bottom'
  5. local topPistonColor = colors.black
  6. local bottomPistonColor = colors.white
  7. local upMotorColor = colors.green
  8. local downMotorColor = colors.orange
  9.  
  10. function enableColor(color)
  11.   rs.setBundledOutput(bundleCableSide, colors.combine(rs.getBundledOutput(bundleCableSide), color))
  12.   os.sleep(sleepTime)
  13. end
  14.  
  15. function disableColor(color)
  16.   rs.setBundledOutput(bundleCableSide, colors.subtract(rs.getBundledOutput(bundleCableSide), color))
  17.   os.sleep(sleepTime)
  18. end
  19.  
  20. function resetColors()
  21.   rs.setBundledOutput(bundleCableSide, 0)
  22.   os.sleep(sleepTime)
  23. end
  24.  
  25. function pulseColor(color, repeatNbr, delay)
  26.   for i=1,repeatNbr do
  27.     enableColor(color)
  28.     os.sleep(delay)
  29.     disableColor(color)
  30.     os.sleep(delay)
  31.   end
  32. end
  33.  
  34. function doorUp(num)
  35.   pulseColor(upMotorColor, num, .18)
  36. end
  37.  
  38. function doorDown(num)
  39.   pulseColor(downMotorColor, num, .18)
  40. end
  41.  
  42. function topPiston(boolVal)
  43.   if boolVal
  44.     then
  45.       enableColor(topPistonColor)
  46.     else
  47.       disableColor(topPistonColor)
  48.     end
  49. end
  50.  
  51. function bottomPiston(boolVal)
  52.   if boolVal
  53.     then
  54.       enableColor(bottomPistonColor)
  55.     else
  56.       disableColor(bottomPistonColor)
  57.     end
  58. end
  59.  
  60. function openDoor()
  61.   topPiston(false)
  62.   doorUp(1)
  63.   bottomPiston(true)
  64.   doorUp(6)
  65.   topPiston(true)
  66. end
  67.  
  68. function closeDoor()
  69.   topPiston(false)
  70.   doorDown(6)
  71.   bottomPiston(false)
  72.   doorDown(1)
  73.   topPiston(true)
  74. end
  75.  
  76. function resetDoor()
  77.   openDoor()
  78. end
  79.  
  80. function resetPistons()
  81.   topPiston(false)
  82.   bottomPiston(false)
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement