Download at bottom of page!!
I would firstly like to thank
Ultheanfor helping clear up the code.
The program is a simple 2 X 1 tunnel digger with user input and block placing/torch placing. I left it simple because it's for beginners!
Now onto the code!
print("How far?") dist = tonumber(read()) n = 1 for i = 1, dist do while turtle.detect() do turtle.dig() sleep(0.25) end turtle.forward() turtle.digUp() n = n + 1 if not turtle.detectDown() then turtle.select(2) turtle.placeDown() end if n == 7 then turtle.turnLeft() turtle.dig() turtle.select(1) turtle.place() turtle.turnRight() n = 1 end end
FIRSTLY, we state that if the turtle detects a block below, do the following:
The explanation for this one is fairly straight forward.
Firstly the program prints "How far?" and then states that n [or number] is equal to 1. Next it states that dist is equal to read which we have made it read as a number using tonumber, otherwise it will just read a string.
for i = 1, dist do
I don't know if you have noticed in my other tutorials, but I use this line of code all the time. It's an easy to understand input loop of sorts. It loops the following code "dist" times, which we stated before as a read number.
The following code:
turtle.select(1) turtle.dig() turtle.forward() turtle.digUp() n = n + 1
This is easy to understand, the turtle selects slot 1, digs, moves forward and mines up. It then sates that n, which before we made equal 1, is now n + 1. So n now equals 2.
Next in the code, we state that if n equals 7 (n gets 1 higher every time n = n + 1) then do the following:
The turtle then turns left, digs once, selects slot 1, places it (slot one should be torches) and then turns right to continue BUT we now minus 6 from n, leaving n to equal 1 once again.
SECONDLY we state an else. This else is from before, where we stated that if turtle.detectDown() then:
But if the turtle DOESN'T detect down, the else comes into play. All it does is:
select slot 2, place downwards. In slot 2 there SHOULD be cobble, and if there isn't a block below it, it places cobble. Making a nice path for you!
I hope you enjoyed this and found it useful. Download for the program is below:
RAWR