turtle.refuel(1) sleep(1) while true do turtle.detect() end if false then turtle.forward() turtle.attack() else turtle.turnLeft() turtle.turnLeft() end
whats wrong with my program?
Started by ironwiccan, Jun 17 2013 11:49 PM
4 replies to this topic
#1
Posted 17 June 2013 - 11:49 PM
I'm trying to make a turtle that patrols a hallway and turns around at the ends, but it stops at the wall...help?
#2
Posted 18 June 2013 - 12: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.
#3
Posted 18 June 2013 - 01:09 AM
Sorry. I guess I had an older version saved on my phone. Ill post the rest asap
#4
Posted 18 June 2013 - 04: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:
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
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
#5
Posted 18 June 2013 - 07:39 PM
I'm thinking this is what you want:
In English readable form:
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.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











