'ycor() 'if' condition in turtle graphics game not being met for some odd reason

I am quite new to python (using python 3.10 interpreter) and I am creating a turtle traffic game where if the turtle object (player) gets to a certain y coordinate (towards the top of the screen) it triggers a method for the object. I've been stuck on figuring out why my condition is not being met (please see some screenshots below). I want the code to trigger the print statement ("reached") when the ycor() of the turtle object is > 100. I can't seem to pinpoint where I'm going wrong. Any help is greatly appreciated.

Screenshot of my code and the game screen



Solution 1:[1]

The only problem with your if statement is where it is located. Currently it's at top level, among a bunch of other code that you expect to only run once. Like that other code, the test is being run once, right at the start of the program. Since (presumably) the turtle starts below the finish line, you're not ever going to see it print the message.

You can fix the problem by moving the if statement into the code that moves the turtle, probably part of the Player class. That code runs each time the turtle moves, so it will repeat the test each time too.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Blckknght