Advertisement
lucifersamfr

TankLevelSupervisor

Sep 10th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. side = "right"
  2. wait = 30
  3. lowLiquidLevel = 100000
  4.  
  5. tank = peripheral.wrap(side)
  6.  
  7. --disable production by default
  8. rs.setOutput("back",true)
  9. refilling=false
  10.  
  11. function tankAmount()
  12.     tanksTable = tank.getTankInfo("unknown")   
  13.     maintank = tanksTable[1]
  14.     return maintank.amount
  15. end
  16.  
  17. function tankCapacity()
  18.     tanksTable = tank.getTankInfo("unknown")   
  19.     maintank = tanksTable[1]
  20.     return maintank.capacity
  21. end
  22.  
  23. function tankIsLow()
  24.     return tankAmount() < lowLiquidLevel
  25. end
  26.  
  27. function tankIsFull()
  28.     return tankAmount() > tankCapacity()-1000
  29. end
  30.  
  31. function printStatus()
  32.   status=""
  33.   if refilling then status="refilling" else status="filled" end
  34.     print("Tank Status :   "..status.." ("..tankAmount().."mB / "..tankCapacity().."mB)")
  35. end
  36.  
  37. while(true) do
  38.   print("...Sleeping for "..wait.."s...")
  39.   sleep(30)
  40.   printStatus()
  41.  
  42.   if tankIsLow() then
  43.     if refilling==false then
  44.       --Resume production when level is low
  45.       print("Tank level is low : production will be resume.")
  46.       rs.setOutput("back",false)
  47.       refilling=true
  48.     end
  49.   else
  50.     if tankIsFull() and refilling then
  51.       --Stop the production when the tank has been refilled
  52.         print("Tank level is full : production will be paused.")
  53.         rs.setOutput("back",true)      
  54.     end
  55.   end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement