| Reference | Downloads | Github

Fixed experiment duration in builder (as opposed to fixed number of trials)

Hi there,
I want to develop a simple experiment in which the total duration is fixed; this means that rather than fixed number of trials, what I need is fixed duration from when the experiment starts (i.e., after instructions and training trials to familiarise with the task) until it ends and in this way faster participants will do more trials. Is there any way to do this using the builder? By now I really couldn’t come up with any idea on how to do this using the builder. Any input is more than appreciated!

Thanks very much in advance!

Hey Ole,

This might only be doable in the builder using code-blocks.
You could save the time of the start of the first trial. Either do this in the “End Routine” tab of the last instruction, or in the “Begin Routine” tab of the trial. The second option would however require some “if firstTrial == True:” satatement so it isn’t reset every trial!

Then you can just check each frame wether the time is up, and if that is true, force the End of the routine if it is.
To get out of the trial loop you can trigger a “break” statement in the “Begin Routine” tab, as it is plced before the “frame loop” of the trial. So all in all it would look a bit like this:

“End Routine” Tab of the last instruction:

myStartTime = globalClock.getTime()
timeUp = False

“Begin Routine” tab of the Trial:

if timeUp:

“Each Frame” tab of the Trial:

if globalClock.getTime() - myStartTime > 500: #Or however long you need
    timeUp = True
    continueRoutine = False

Maybe there’s something I don’t see, or someone else knows a more efficient way, but I hope this is a start. :wink:


1 Like

thanks that was a very helpful and clear answer. It all makes sense, I’ll implement it and if I have problems I’ll post them here. Of course if anyone wants to add other methods or suggestions that may be useful in general, those are more than welcome.

Thanks again!

Quick upddate: it works like a charm :slight_smile:

I suck so bad with python that it took me a bit to understand that I should put a coloum : after

if globalClock.getTime() - myStartTime > 500

once I understood that, it works as requested. Thanks again for your help,definitely super useful!

That missing colon was also my bad, sorry for that.
But I’m happy that you worked it out in the end. :wink: