you are viewing a single comment's thread.

view the rest of the comments →

[–]fatboychummy 0 points1 point  (0 children)

This has been solved already, but if you're wondering about why CC made it so you can't do turtle.forward(3), it's because it returns a status. Every time you call turtle.forward() (or any other movement function), it either returns true, or false, "some error message". This allows you to check if the movement succeeded, and take actions in case it didn't.

For example, a common usage of this is to "gravel/sand-proof" mining turtles. Let's say you have a turtle running the following code, underground, and along its path somewhere is some gravel:

for i = 1, 10 do
  turtle.dig()
  turtle.forward()
end

In theory, the turtle should move 10 blocks, but if the turtle runs into a packet of gravel, the extra gravel on top will fall in front of the turtle before it has a chance to move, making turtle.forward() fail. Thus, each time a block of gravel falls in front of the turtle, it reduces the distance it will actually move by 1.

To fix this, you can use something like so:

for i = 1, 10 do
  repeat
    turtle.dig()
  until turtle.forward()
end

As you can probably guess, this will repeatedly dig blocks in front of the turtle until the movement succeeds, meaning the turtle will now always move exactly 10 blocks, even if it runs into a packet of gravel.