Help with Backwards Digit Span Termination

**OS Windows-10
**PsychoPy 2023.2.3

Hi! I am trying to create a backwards digit span that terminates completely after the participant makes three mistakes in the same trial. However, the code is stuck in a loop of the first trial, regardless of how the participant responds.

Code:

mistakes = 0  
consecutive_incorrect = 0  

if textbox.text == ''.join(reversed(str(digits))):  
    correct_digits = 1
    fbTxt = 'Correct!'
    consecutive_incorrect = 0  
else:  
    correct_digits = 0
    fbTxt = 'Incorrect'
    mistakes += 1  
    consecutive_incorrect += 1  

thisExp.addData('correct_digits', correct_digits)
thisExp.addData('total_mistakes', mistakes)

if consecutive_incorrect >= 3:
    last_level = level  
    digitspan_trials.finished = True  
    digitspan_blocks.finished = True 
    fbTxt = "This experiment is now over."

Thanks for any help!

Is this in the same code component tab as the rest of your code?

Yes, everything is in End Routine except for “mistakes = 0” in Begin experiment and the “consecutive_incorrect >= 3:” if statement at the end, which is in End Experiment.