Advertisement
Link712011

Simple refuel

Apr 14th, 2016
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.84 KB | None | 0 0
  1. function select_fuel(from_slot)
  2.     local slot
  3.     local success
  4.    
  5.     slot = 1
  6.     success = false
  7.     while slot <= 16 do
  8.         turtle.select(slot)
  9.         if turtle.refuel() then
  10.             success = true
  11.         end
  12.         slot = slot + 1
  13.     end
  14.     return success
  15. end
  16.  
  17. function print_fuel_status()
  18.     print("Fuel level: ", turtle.getFuelLevel(), "/", turtle.getFuelLimit())
  19. end
  20.  
  21. function check_fuel()
  22.     local sleeptime
  23.     local try
  24.    
  25.     try = 0
  26.     sleeptime = 0.5
  27.     while turtle.getFuelLevel() < turtle.getFuelLimit() do
  28.         if not select_fuel() then
  29.             print("Waiting fuel... retrying in " .. sleeptime .. " seconds.")
  30.             print_fuel_status()
  31.             sleep(i)
  32.             sleeptime = 2
  33.             try = try + 1
  34.         else
  35.             sleeptime = 0.5
  36.         end
  37.         print_fuel_status()
  38.         if try > 500 then
  39.             print("Master forgotten me...")
  40.             return false
  41.         end
  42.     end
  43.     return true
  44. end
  45.  
  46. check_fuel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement