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

Making a turtle retry until successful?

Started by Arery, 16 July 2014 - 08:13 AM
Arery #1
Posted 16 July 2014 - 10:13 AM
So, for my first ever lua/computercraft program, I've tried making a turtle fence off a 128*128 area.
The program lloks like this:
http://pastebin.com/FWBUHfFh

It's working, but because of the many curious mobs that often feela need to place themselves in front of the turtle, the turtle.forward() command/line/whateveryoupeoplecallit sometimes fails.
With the current program, the turtle doesn't mind that it didn't move, and just continues running, which causes the fence to not be 128*128.

what I want to do is make the turtle keep trying turtle.forward() until it gets a succesful result.

So how does one go about doing that?

Thanks in advance
hilburn #2
Posted 16 July 2014 - 10:25 AM
Something like this?

while not turtle.forward() do end

this will get stuck, wait for the obstruction to go away and then carry on, you could also add in turtle.attack() which will "encourage" mobs out of the way, but if you follow too closely and it hits a creeper, it will blow a hole in the ground you need to clean up.

It will not be able to handle getting stuck on blocks as those will never move out of the way but I'm assuming you'll handle that with the rest of your code
Edited on 16 July 2014 - 08:33 AM