Advertisement
25hz

Turtle - Dig 1 x 3 tunnel w/torches & return

Oct 21st, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. -- This script digs a 1 x 3 high tunnel
  2. -- to the length you are prompted,
  3. -- places a torch on the side wall,
  4. -- and returns.
  5. -- Put torches in slot 16 (bottom right corner)
  6. --
  7. -- Place the turtle on the floor level of your tunnel
  8. --------------------------------------------------------
  9.  
  10. function digIt()
  11.   while turtle.detect() do
  12.        turtle.dig()
  13.        os.sleep(1.0)
  14.   end
  15.   turtle.forward()
  16.   while turtle.detectDown() or turtle.detectUp() do
  17.     turtle.digUp()
  18.     turtle.digDown()
  19.   end
  20. end
  21.  
  22. function placeTorch()
  23.   turtle.back()
  24.   turtle.select(16)
  25.   turtle.placeUp()
  26.   turtle.forward()
  27.   turtle.select(1)
  28. end
  29.  
  30. -- this sets the initial variable values ----------------
  31. local run = 0
  32. local j = 0
  33. local k = 0
  34.  
  35. term.write("Length of Branch?  ") -- You are prompted to enter a tunnel length ----------------
  36. run = read()
  37.  
  38. ----------------------------------------------------------------------------------------
  39.  
  40. -- This is the main command to dig the tunnel ----------------
  41. turtle.up()
  42. for i = 1, run do
  43.   k = i - 1
  44.   j = k % 5  -- This determines how many squares to place a torch ie: 5 ----------------
  45.   if j == 1 then
  46.     placeTorch()
  47.   end
  48.   digIt() -- this digs the tunnel length you typed in ----------------
  49. end
  50.  
  51. -- this places a torch at the end of the tunnel, drops to the floor,
  52. -- turns around, and returns to the start
  53. turtle.select(16)
  54. turtle.placeUp()
  55. turtle.turnRight()
  56. turtle.turnRight()
  57. turtle.down()
  58.  
  59. for i = 1, run do -- this tells the turtle to head back the same number of squares it dug ----------------
  60.   turtle.forward()
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement