Fixation routine with random duration before a movie routine behaves with wrong duration

Hi,

I’m building my task in the builder GUI and need to publish it on pavlovia later, but when I test it locally, something strange happened.

in my task, there is a fixation routine with a text component and the code component on top of it. the code component is as follows:

begin experiment: import random

begin routine: iti = random.choice([0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5]).

The text component is simply a + sign with a duration ‘$iti.

in the next routine where I show my movies with a movie component. it is set to start at 0, and duration is set to blank. Movie was set to randomized at every repeat.

The problem is that the duration of the fixation always exceed the iti variable, it’s about 3-second long (as long as my movie stim).

I’ve tried to set a routine timeout under the fixation, and it didn’t help. I have also tried checking “force end of routine” on the movie stim on’off, and it didn’t help either.

However, when I disabled the movie routine/component (the movie component is the only thing in my movie routine), the fixation duration finally behaved normal.

Obviously, I must show my movie with a varying fixation interval in front of it, im just wondering what the root cause of this issue and how to fix it.

Thanks in advance :slight_smile:

Hello @Fan_Yang

If you want to run the experiment online, you cannot import Python libraries.

One way to randomly select an itiis as follows

iti = randchoice([0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5])

There is no need for a $ if there one precedes an argument. itishould if sufficient.

You can put everything in one routine. Simply use the duration of your itias the starting point of your movie.

Which version of PsychoPy are you using?

Best wishes Jens

Thanks for the reply @JensBoelte !

I’ve editted the task based on your suggestion. I delete the call for the library of ‘random‘ and used randchoice to pick a iti. the ‘$‘ was also removed from iti for duration.

However, when I merged the movie with the fixation into one routine, the fixation wont show up. Instead, when a movie was done playing and a key_resp was made on a response routine, the screen stayed on the response routine for 3-4 seconds and started play the next video after. This behavior is similar to my timing situation in my oroginal post where a fixation cross will last 3-4 second instead of being controlled by the iti variable

The fixation cross is only visible when movie and fixation cross (text component) were seperated into different routines. The component in this routine was ordered as code → fixation → movies. Only one line of code was in the code component “iti = randchoice([])“. The variable ‘iti’ defines both the duration (s) of the fixation cross and the start (s) of the movie.

(Movie backend is ffpyplayer in case you want to know, and psychopy yielded error messages in the runner when switched to other backend)

Below are the psychopy version:

PsychoPy 2026.1.1

Paths to files on the system:
userPrefsFile: C:\Users\Power House\AppData\Roaming\psychopy3\userPrefs.cfg
appDataFile: C:\Users\Power House\AppData\Roaming\psychopy3\appData.cfg
demos: C:\Program Files\PsychoPy\lib\site-packages\psychopy\demos
appFile: C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\PsychoPy.py

System Info:
Operating System: Windows-10-10.0.26200-SP0
Processor: Intel64 Family 6 Model 154 Stepping 4, GenuineIntel
CPU freq (MHz): 1700.0
CPU cores: 10 (physical), 12 (logical)
Installed memory: 16579715072 (Total), 5827661824 (Available)

Python info:
Executable path: C:\Program Files\PsychoPy\pythonw.exe
Version: 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
(Selected) Installed Packages:
numpy (2.2.6)
scipy (1.14.1)
matplotlib (3.10.8)
pyglet (1.4.11)
PyGLFW [not installed]
pyo 1.0.5
psychtoolbox (3.0.19.14)
wxPython (4.2.5)

OpenGL Info:
Vendor: Intel
Rendering engine: Intel(R) Iris(R) Xe Graphics
OpenGL version: 4.6.0 - Build 32.0.101.7080
Shaders supported: True
(Selected) Extensions:
GL_ARB_multitexture: True
GL_EXT_framebuffer_object: True
GL_ARB_fragment_program: True
GL_ARB_shader_objects: True
GL_ARB_vertex_shader: True
GL_ARB_texture_non_power_of_two: True
GL_ARB_texture_float: True
GL_STEREO: False
max vertices in vertex array: 1048576

Hello @Fan_Yang

Do you mind to post the relevant routines instead to describing them? Alternatively you could post a toy-version your experiment including some toy-material.

Best wishes Jens

I’m more than happy to!

Thanks again for your time and efforts @JensBoelte :slight_smile:

In the zip file, there are 6 videos (screen recording of an empty area on my desktop), a data file contained data from this toy task, the task itself plus the condition excel file.

toy.zip (3.1 MB)

pilot_toy_2026-04-07_11h15.26.947.csv (2.5 KB)

Hello @Fan_Yang

Soory, but I have no idea why your experiment does not work. As soon as one adds the movie, timing seems to be off. One can not even ends the instruction page with a single keypress. All video players except ffplayer complain that one references a local variable before assigning it. This might be due to the fact that you load your movies via a condition file, althought this should work. The fixation cross is (sometimes) shown, it is just covered by the movie. I checked that changing the location of the fixation cross.

When I added a routine at the beginning of the experiment that loaded a dummy movie which was not played (start = 0 and duration = 0), everything looked as intended. That is perhaps your work around?

Best wishes Jens

Thanks for taking the time to investigate!

The workaround fixed the problem nicely. I’ll mark this as solved in case more users encounter this issue.

If you don’t mind me asking, how did you come up with this workaround? I’m trying to get more insight into how PsychoPy works :slight_smile:

@Fan_Yang

I tried the other video backends and received an error message stating that I was attempting to access a local variable before initialising it. I added a dummy routine before the trial routine in an attempt to solve the local variable problem, but this was unsuccessful. Then I switched back to ffpyplayer, leaving the dummy routine in place. And voilà, it worked! But don’t ask me why.

In any case, I think both behaviours are due to bugs.

Best wishes Jens