16 posts
Posted 15 August 2014 - 10:32 PM
http://www.pastebin.com/gSLFM8NTThe part of this code where it should be printing "Moved Forward" isn't working. Its not giving me an error, its just not printing it. Why?
The code I'm having trouble with is near the end.
Edited on 15 August 2014 - 08:32 PM
31 posts
Location
Bodafors, Sweden
Posted 15 August 2014 - 11:10 PM
Replace:
turtleWentForward = turtle.forward()
if turtleWentForward == true then
With just:
if turtle.forward() then
Edited on 15 August 2014 - 09:11 PM
16 posts
Posted 15 August 2014 - 11:25 PM
Thank you, but for curiosity's sake, why doesn't my code work? I feel like it should
1080 posts
Location
In the Matrix
Posted 15 August 2014 - 11:31 PM
Replace the parts that are just like that by doing the same.
16 posts
Posted 16 August 2014 - 12:10 AM
Replace:
turtleWentForward = turtle.forward()
if turtleWentForward == true then
With just:
if turtle.forward() then
Actually this isn't working
http://www.pastebin.com/Qb4zad9K
7508 posts
Location
Australia
Posted 16 August 2014 - 02:01 AM
Well of course, making that change changes nothing with how the program works, it is just a more readable solution. What is the error that you're getting? or is it just simply not moving, if so have you fuelled the Turtle?
16 posts
Posted 16 August 2014 - 07:49 AM
Turtle is fueled, not getting an error, just not printing "Moved Forward"
7508 posts
Location
Australia
Posted 16 August 2014 - 09:22 AM
Can we get a screenshot of your setup, as well as a screenshot after running the 'refuel' program.
7083 posts
Location
Tasmania (AU)
Posted 16 August 2014 - 11:41 AM
detectBlock = turtle.detect()
if detectBlock == true then
turtle.dig()
turtle.forward() -- Move forward, ignore the result.
end
if detectBlock == false then
turtle.forward() -- Move forward, ignore the result.
turtleWentForward = turtle.forward() -- Try to move forward *again*, store the result.
if turtleWentForward == true then -- If the *last* move attempt was successful, then...
print("Moved Forward")
end
end
You've got three attempts to move piled in there, and you only check the results of the one which is nearly sure to fail (because the turtle
just moved forward, and hence likely has a block in front of it) - thus the print statement will seldom be executed.
Try it like this:
while turtle.detect() do -- As long as turtle.detect() returns true,
turtle.dig() -- repeat this.
end
while not turtle.forward() do -- Until turtle.forward() returns true,
turtle.attack() -- repeat this.
end
print("Moved Forward")
It's also worth being clear about your issues - don't say things "aren't working", describe what happens instead. People here are assuming the turtle isn't moving at all.
Edited on 16 August 2014 - 10:11 AM