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

Turtle can become insane - turtle.turnLeft() and turtle.forward() return true, but don't budge

Started by edwin4, 17 March 2013 - 02:37 AM
edwin4 #1
Posted 17 March 2013 - 03:37 AM
Turtle goes insane - returns "true" to turtle.forward() but doesn't budge. Turtle can't turn either. (No, it's not a fuel issue)

I am running CC 1.51 ironchest 288, forge 582, on a 64-bit ubuntu/oracle Java 1.7 SMP server.

Generally, code doesn't execute properly (esp turtle.compare() ) after awhile

So, I don't know of any situation in which a turtle can return true to turtle.forward() and not have moved. Also, turtle.turnLeft() or turtle.turnRight() … basically, if you stop the script, and restart, everything's fine. But after one loop, the script becomes useless. The script is mostly not mine, so narrowing down what function may be triggering this madness is unlikely, I'm hoping a developper has a debugger that can just run this and introspect properly.

http://pastebin.com/V2APXeRW

so, from a turtle:
pastebin get V2APXeRW treelogger
and
pastebin get gqXgsQm5 loggerSettings
(the name is important, case sensitive)
Deploy an axe-equipped turtle on the ground in front of a large (40x40) field <=– stuff is built ahead and to the left
put 64 saplings (I use birch) in slot 1
put 64 earth in slot 2
put 1 log of the same type of tree as your sapling in slot 3
put 64 coal/charcoal in slot 15

run the script: treelogger

Wait for the bot to return home
Replace the bot in the same spot (it will try to refill from chests, but don't bother about that)
refill the bot with the same quantities
re-run "treelogger"

When the turtle returns home, it will try to turn around, move forward twice, and refuel. The bug manifests in the "refill" section - the turtle just tries to move forward, it succeeds (there's code printing the boolean, which prints "true" but the turtle doesn't move. In fact, the turtle didn't even turn around. At this point, expect all kinds of other wierdness in the code too.

If you don't witness this madness, just rerun the bot a few more times, it'll show up eventually.
————-
I agree it looks like a script bug, but, really, under what circumstances can a script get into a state where turning around returns true, but it doesn't turn around? And also, under what circumstances can it get into a state where moving forwards returns true, but it doesn't actually move anywhere?
Also, you may be interested to know, this used to work correctly in regular CC1.5 / minecraft 1.4.7…
Snippet:
print("trying to refill")
turtle.turnLeft()
turtle.turnLeft()
print ("1:" ..tostring(turtle.forward()))
print("2:"..tostring(turtle.forward()))
print("turtle moved?")

When the "bug" happens, The console actually prints
trying to refill
1: true
2: true
turtle moved?

I can't find anywhere in the code where the functions themselves are overwritten (if that's even possible) so… I doubt turtle.turnLeft() itself is going elsewhere… though… I'll try printing that address "before/after".
Cloudy #2
Posted 17 March 2013 - 05:59 AM
If you restart the script and it runs fine, then it isn't a CC bug and it is something in the script.

How do you know the functions turn true? What are your indications this is true? (Line numbers please)
edwin4 #3
Posted 18 March 2013 - 06:31 PM
Excellent point, how embarassing, the line numbers 1062 and 1063 are the "forward" commands, but the turn doesn't appear to be "instrumented" I guess I'm getting senile. Meanwhile, if it really IS the script, I suppose the only logical explanation is that the turtle.forward() function is somehow being overridden? I just assumed that the …um… "lua instance"… can become insane, thus it could still be a CC issue.

I shall Go Forth And Investigate and apologize for potentially having wasted your time.