| Reference | Downloads | Github

Exit a Routine inside a Loop

OS : Win10
PsychoPy version : v2020.1.3
Standard Standalone? Currently using the builder, but I need to run online experiments with Pavlovia.

I have this pilot experiment (Pavlovia) with video stimuli to be presented in a randomized order in a loop.
What I want to do is to stop the video and so the associated Routine when a key (either ‘p’ or ‘d’) is pressed. To do so I added the following code component:

What happens both in Psychopy and Pavlovia is that the video continue playing, no key can stop it and I have no error messages.

Any help is appreciated.
Thanks a lot!

Why are you setting AutoDraw to True at the point you want to stop the video?

You should add movie_randomized.stop() to stop the movie just above continueRoutine=False

Hi @wakecarter
thanks for the fast reply. You are right, I posted an old picture.
This is the updated version:

In both Psychopy and Pavlovia I’m not able to stop the video and go to the following trial.

Your indent on the line “for key in event.getKeys():” means that it will only check to see if a key is pressed to stop the movie before it is started.

Yes it is what I need. But when I press either ‘p’ or ‘d’, the video does not stop or exit the routine.
I tried also to increase the time interval if t > .1 and moviestarted == 0 from .1 to .5, with no improvements.

I am sure that you don’t want to stop the movie before it is started

Ok, I see. I changed the code like this:

if t > .1 and moviestarted == 0:
     moviestarted = t
for key in event.getKeys():
   if key in ['p','d']:
       continueRoutine = False

Thanks a lot!

1 Like