286 posts
Posted 18 June 2013 - 12:49 AM
I'm trying to make a turtle that patrols a hallway and turns around at the ends, but it stops at the wall…help?
turtle.refuel(1)
sleep(1)
while true do
turtle.detect()
end
if false then
turtle.forward()
turtle.attack()
else
turtle.turnLeft()
turtle.turnLeft()
end
8543 posts
Posted 18 June 2013 - 01:08 AM
Um, no. That program literally doesn't do anything. It would refuel, sleep for one second, and then sit there using turtle.detect() forever. Please give us your entire actual code so that we can help fix it.
286 posts
Posted 18 June 2013 - 02:09 AM
Sorry. I guess I had an older version saved on my phone. Ill post the rest asap
3 posts
Posted 18 June 2013 - 05:04 PM
I'm just starting out but…. isn't the first "end" closing the "while" loop? :/ so pretty much it'll just keep detecting…
Try this:
function ______
turtle.refuel(1)
sleep(1)
while true do
if turtle.detect() then --If it detects then...
Do
Stuff
end
end
Also, this will refuel and sleep once, then jump into the circle of whatever. So maybe you don't want a while true loop. Try a repeat or for loop?
:)/>
P.S you can put "if not…." if you want to reverse what you want to do
1688 posts
Location
'MURICA
Posted 18 June 2013 - 08:39 PM
I'm thinking this is what you want:
turtle.refuel(1)
while true do
if not turtle.detect() then
turtle.forward()
turtle.attack()
else
turtle.turnLeft()
turtle.turnLeft()
end
end
In English readable form:
Refuel the turtle.
Do the following while true is true:
Do the following if the turtle does not see a block in front:
Go forward.
Attack.
Otherwise:
Turn around.