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

Problem with turtle ignoring if statements

Started by Darkveld, 19 April 2014 - 02:17 AM
Darkveld #1
Posted 19 April 2014 - 04:17 AM
I am attempting to make a free-form hole filling turtle, but it keeps ignoring the nested if statements, it instead just keeps running the while loop while missing the if statements inside completely.

http://pastebin.com/4yLKaD6H

The turtle is supposed to hit a wall, detect if the wall is a specific block, if its not then it will navigate around the block, turn around and start a new line until it finally hits the target end block.

Currently the turtle hits the first wall, announces that it has hit a wall, and then just loops back to the beginning of the while loop and ignoring the if statement for noticing a wall has been hit.
Bomb Bloke #2
Posted 19 April 2014 - 05:11 AM
So you're saying it just starts spamming "i have reached a wall" into the console, or…?

Main issue I'm seeing is your use of "local" on line 16, which would prevent the script from ever completing, but I can't see anything too obvious that'd cause the behaviour you're describing.
Darkveld #3
Posted 19 April 2014 - 08:55 AM
That is correct, the turtle just keeps spamming that it has hit a wall after doing so, but never triggers the condition at line 25 even though the debug print shows that it passes through the whole while statement each time.

I have solved the previous problem by moving the problematic wall detection code right into the function instead of depending on the while loop to find the if statement, now however I seem to lack an understanding on os.pullevent, as I keep getting a attempt to call nil when pulling a turtle_inventory event.

New code at: http://pastebin.com/igzUAQ7Z

Would still like to know why the previous problem happens though so I can avoid it in the future.