Advertisement
hevohevo

ComputerCraft Tutorial: auto_refuel

Jun 7th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. -- #########################################
  2. -- auto refuel
  3. -- version 0.1
  4. -- http://hevohevo.hatenablog.com/
  5.  
  6. -- You must prepare many many fuel items.
  7.  
  8. -- Config
  9. local suck = turtle.suckDown
  10. local drop = turtle.dropDown
  11.  
  12. -- Functions
  13. function myGetFuelLevel()
  14.     local tmp = turtle.getFuelLevel()
  15.     print("Fuel Level: "..tmp)
  16.     return tmp
  17. end
  18.  
  19. function dropAll()
  20.     for i=1,16 do
  21.         if turtle.getItemCount(i) > 0 then
  22.             turtle.select(i)
  23.             drop()
  24.         end
  25.     end
  26. end
  27.  
  28. -- main
  29. local limit_level = turtle.getFuelLimit()
  30.  
  31. -- see ComputerCraft.cfg
  32. if not limit_level or limit_level == 0 then
  33.     error("no FuelLimit")
  34. end
  35.  
  36.  
  37. local args = {...}
  38. local goal_level = tonumber(args[1])
  39.  
  40. if #args == 0 then
  41.     print("FuelLimit is ",limit_level)
  42.     myGetFuelLevel()
  43.     while true do
  44.         write("\nReally? (y/n): ")
  45.         local str = read()
  46.         if str == "n" or str == "N" then
  47.             error("terminated")
  48.         elseif str=="Y" or str=="y" then
  49.             goal_level = limit_level
  50.             break
  51.         end
  52.     end
  53. end
  54.  
  55. turtle.select(1)
  56. while (goal_level > myGetFuelLevel()) and suck() do
  57.     local status, error_msg = turtle.refuel()
  58.     if not status then
  59.         print(error_msg)
  60.         break
  61.     end
  62. end
  63. dropAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement