Q009

Turtle - Torch placer

Nov 10th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. local usedFuel = 0
  2. local usedTorches = 0
  3.  
  4. function fuelChk()
  5.     if turtle.getFuelLevel() < 20 then
  6.         turtle.select(1)
  7.         if turtle.refuel(1) == false then
  8.             print("Out of fuel!")
  9.             exit()
  10.         end
  11.         usedFuel = usedFuel + 1
  12.     end
  13. end
  14.  
  15. function doStuffAndThings()
  16.     print("Thank you for using our amazing freaking program")
  17.     print("Q009 says hello")
  18.     print("Please specify the space interval")
  19.     local space = io.read()
  20.     space = tonumber(space)
  21.     local t = space
  22.     if space < 1 then space = 1 end
  23.    
  24.     while true do
  25.         fuelChk()
  26.         if turtle.getItemCount(2) == 0 then
  27.             print("Out of torches!")
  28.             exit()
  29.         end
  30.        
  31.         while turtle.detect() do
  32.             sleep(5)
  33.         end
  34.        
  35.         if t == space then
  36.             turtle.select(2)
  37.             while turtle.detectDown() do
  38.                 sleep(1)
  39.             end
  40.             turtle.placeDown()
  41.             t = 0
  42.         else
  43.             t = t + 1
  44.         end
  45.        
  46.         turtle.forward()
  47.        
  48.     end
  49.  
  50.     print("Done! Used fuel: " .. usedFuel .. " | placed torches: " .. usedTorches)
  51. end
  52.  
  53. doStuffAndThings()
Advertisement
Add Comment
Please, Sign In to add comment