Randomize duration of a Routine in Builder

It is only in the text component settings. I also tried ‘duration (frames)’, ‘frame N’ and ‘condition’.


there is no need to use “set every repeat” if you don’t change the stimulus. It can be constant.

Which psychopy-version are you using? I’m using 2020.2.10

Best wishes Jens

No, a more recent one: PsychoPy 2021.1.2


what happens when you set your PsychoPy to use an older version (edit experiment settings → use PsychoPy version)?

Best wishes Jens


if bool(asarray($fixDur)):
                ^ (arrow on dollar sign)

SyntaxError: invalid syntax

Experiment ended.


does this RandFix.psyexp (13.5 KB) run?

Best wishes Jens

Yes, it looks like this:

And gradually counts down/


looks good. It is not a count-down. :wink: The number in middle stays on screen for a period lasting between 3 - 3.5 sec. How “large” is your experiment? If it is not too large, you could use this example to build your experiment.

Best wishes Jens

it’s from 250 to 500 stimuli. is it too big to use what you’ve sent me?

@JensBoelte means in terms of numbers of routines.

500 stimuli could still just be one routine with a couple of components in one loop.

Thank you. When I copy-paste your code in my experiment, weirdly it refuses to work. Again because of $ dollar sign in the duration line. I guess the only chance is to rebuild my experiment in your file. Sounds like nonsense, but we have what we have :frowning:

Have you tried without the dollar sign?

oh my! it finally works. thank you both @JensBoelte and @wakecarter very much :clap:

When I follow you steps, it can visualize the stimulus, but once the time is over, the whole experiment stops and does not go to the next step.
I have the following error:

Any ideas?

Thank you very much :slight_smile:

Do you have movie.stop() or similar in a code component? Can that code be reached before the movie is first started?

Hi @wakecarter

Thanks for your reply. I don’t have a movie.stop() or similar in my code component.
In the ‘Begin Routine’ I have:

sstim_dur =[2,3,1.5]#[20,24,28,32,36,40,44,48,52,56,60]#random()*(3.5-3)+3
stim_dur = sstim_dur.pop()

and in the ‘End Routine’ I have:

thisExp.addData(“MovDur”, stim_dur)

Please could you show a screenshot your movie component? Specifically the start and end times.

Here you go:

Thank you :slight_smile:

In searching other similar posts I found a thread which suggests that it might be because the movie is buffering.

However, I also saw that you’ve seen that thread so here is my suggestion.

  1. Remove $stim_dur from the duration of the movie (make it blank)

  2. Add the following code to Each Frame

if t > stim_dur:
     continueRoutine = False
1 Like

@wakecarter you are sooo amazing!!! I was putting the code as you said and it worked!!
Thank you so much!

1 Like