Force a loop to end

Hi

Im new to psycopy and coding in general but I’m trying to build an experiment and in said experiment there is an inctructions/test phase. What I’m trying to accomplish is that after the participant does the test phase, he is presented with the question “Do you want to repeat the teste phase or do you want to go to the real experiment?” and depending on his answear, he will either do the test again or advance to the real deal. I tried to write code in wich, if the participant pressed on ‘1’ he’d repeat the test and if he pressed ‘3’, he’d continue to the real deal.

This is what I wrote:

if key_resp_4.keys:

if '3' in key_resp_4.keys:
    trials.finished = True

elif '1' in key_resp_4.keys:
    trials.finished = False

And this is what it looks like: (The code is written in the routine called “Intervalo”)

Thank you in advance, hope someone can help me!

You don’t need elif '1' in key_resp_4.keys: trials.finished = False since that will be the default.

Have you put the nReps for trials to be a large number?

I removed elif ‘1’ in key_resp_4.keys: trials.finished = False

My nReps for trials is 9999

What is happening is that both ‘1’ ou ‘3’ make the loop happen and neither of them make it stop and advance to the next routine

Is your keyboard response called key_resp_4?

Is your code in End Routine?

My mistake, I had my code in each frame because of some things I was trying earlier, thank you so much, It works now!