psychopy.org | Reference | Downloads | Github

Terminate Experiment Based on Specific Interval

I’m trying to accomplish what I thought would be a simple task but has turned out to be fairly difficult. I have created an experiment where a subject is repeatedly presented with a different version of the same trial and due to the number of elements in the trial, there are about 900 different possible trials that the subject could experience. We want the subject to try to get through as many trials as possible in 45 minutes, but have not found a simple way of ending the experiment after 45 minutes.

Using 10 seconds as a practice interval, I’ve tried to write some code that looks like this:

if globalClock == 10:
    core.quit()

The program will just fine, but nothing happens after 10 seconds. Does anyone have any other suggestions?

Hi @Benjamin_Seitz, you have to call the Clock objects getTime method for the clock to have a time returned:

if globalClock.getTime() >= 10:
    core.quit()

Many thanks @dvbridges. That variation didn’t quite work, but this solution did

Begin experiment:
timer = core.Clock()

Every frame:

if timer.getTime() > 10:
    trials.finished = True #core.quit() works too
1 Like

Bear in mind that this time won’t be exact: there is a variable, non-zero, amount of time that elapses between code that runs at the beginning of the experiment’s code and the actual start of the experiment as the subject experiences it. So you might want to start your timer on the first routine of the relevant loop, using code like this in the “Begin routine” tab of a code component:

# start a timer on the first trial:
if your_loop_name.thisN == 0:
    timer = core.Clock()