This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hiperactive's profile picture

How to make turtle move specific distance.

Started by hiperactive, 01 April 2012 - 04:32 PM
hiperactive #1
Posted 01 April 2012 - 06:32 PM
Ok so, I'm a complete noob with all this, so this probably a really stupid question. But how would I make a turtle move a certain number of blocks forward rather than traveling forever?
xuma202 #2
Posted 01 April 2012 - 06:49 PM

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

Where Blocks is the number of Blocks to move
hiperactive #3
Posted 02 April 2012 - 08:08 AM
Thanks so much :3

But how do I put it into a command? Say I want it to move 3 blocks, turn left, then move 3 blocks more?
Cloudy #4
Posted 03 April 2012 - 12:30 AM

function forwardNum(blocks)
  for i= 1, blocks do
    turtle.forward()
  end
end

forwardNum(3)
turtle.turnLeft()
forwardNum(3)
Hidden Monarch #5
Posted 03 April 2012 - 10:16 PM
Thanks so much :3

But how do I put it into a command? Say I want it to move 3 blocks, turn left, then move 3 blocks more?

turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
Cloudy #6
Posted 03 April 2012 - 11:33 PM
Thanks so much :3

But how do I put it into a command? Say I want it to move 3 blocks, turn left, then move 3 blocks more?

turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()

Tell me, how was that any better than my code I just posted? If your code doesn't add anything, why post it?

Maybe I'm being a bit harsh, but if a more elegant solution exists, that should be sufficient :)/>/>