Posted 06 June 2014 - 03:16 AM
Okay, I am a beginner in coding in general. But I have been messing with this piece of code for 30 minutes and I can't get it to do what I want it to. What I want the turtle to do is go forward but when it detects a block in front of it, go up. I've got that down, but when it is cornered with a block above it and in front of it I wanted the turtle to turn around and go forward until it detects there is nothing over it. Then I wanted it to go up and turn back around and continue it's journey. The problem is that when it turns around, it does not stop once it detects a free space above it.
local m = 1
function Tforward()
if turtle.detect() == true then
turtle.up()
end
if turtle.detect() == true and turtle.detectUp() == true and m == 1 then
turtle.turnLeft()
turtle.turnLeft()
local m = 0
end
if turtle.detectUp() == false and m == 0 then
turtle.up()
turtle.turnRight()
turtle.turnRight()
local m = 1
end
turtle.forward()
end
while true do
Tforward()
end
Edited on 06 June 2014 - 01:26 AM