Jump to content




Problem with turtle ignoring if statements


  • You cannot reply to this topic
2 replies to this topic

#1 Darkveld

  • New Members
  • 2 posts

Posted 19 April 2014 - 03: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.

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 19 April 2014 - 04: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.

#3 Darkveld

  • New Members
  • 2 posts

Posted 19 April 2014 - 07: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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users