End loop after time specific routine

Hi y’all.
I want to end loop after two minutes but starting the timer in a specific routine.

I try globalclock but apparently does not work in my case.

Any help is appreciated

Create a clock object in your Begin Experiment code, and just reset it during the routine where you want to start it. If you put an object in the “Begin Experiment” code it has global scope for the experiment. Just make sure you only check it after the routine where you reset it.

Thanks for answering.
Since I’m new to psychopy maybe I don’t fully understand your answer.
In code component I have
startTime = globalClock()
if globalClock.getTime() - startTime >= 120:
trials_2.finished = True
continueRoutine = False

However, now it won’t even open the experiment.

As well I tried:
if t>=4:
continueRoutine = False
But this only cut the routine after 4 seconds of not receiving any clicks.

The second one makes perfect sense to me, t is a built-in timer.

For the first one I was thinking something like this. Note that I am using the before experiment tab. This is very important.

Before experiment:

newClock = core.Clock()

Begin routine:


End routine:

if newClock.getTime() >= 120:
    trials_2.finished = True

(You shouldn’t need continueRoutine since the routine has already ended, but if you want it to end the routine, put this code in the “each frame” tab instead)

What happens with this setup?

Actually, this only cut the routine after 120 seconds of not receiving any clicks, if the participant continues typing, then the routine keeps going.

I want to cut even if the participant continues typing.

I’m sorry for explaining this so far.

Ah, then just put the “end routine” code in the “each frame” tab instead and add continueRoutine = False back into it.

Still the same situation.

Apparently nothing changes. It only ends the routine after no clicks, if I keep typing, the routine continues.

Thanks for the help.

That’s interesting. Could you share your .psyexp file here? It’s possible that PsychoPy has some code forcing the routine to continue as long as its receiving input, but I need to see how the trial is put together to figure it out.

1 Like