If this template helps then use it. If not then just delete and start from scratch.
OS: Mac OS 2026.5.1
PsychoPy version: Studio 2026.2.1
Standard Standalone Installation? (y/n) No, PsychoPy Studio
Do you want it to also run online? (y/n) No
What are you trying to achieve?:
I am showing a Movie component (called video) where the file being shown changes by the conditions file in a trials loop.
I am not totally sure what triggered this error as it was working fine until I renamed the Routine immediately preceding the movie Routine? The renamed ITI Routine does contain a screen-freeze ITI and I did not change that name.
The task errors out when it tries to run the movie routine and returns the error:
UnboundLocalError: local variable ‘video’ referenced before assignment
I notice that in the rendered .py expt file that I can view in the Coder, all of the other Components are initialized at the beginning of the experiment by the automatic Builder code, but the video = visual.MovieStim(...) is only initialized inside the code for the movie Routine? the UnboundLocalError throws because the components = [video, ...] call at the beginning of the movie Routine cannot find the video Component (which has not been initialized at the beginning of the experiment!)
Again, I’m not sure what Builder setting I changed to change when video is auto-initialized by the Builder-code, but this happened while I was working on my task today, so it must be tied to a particular Builder setting I changed.
What did you try to make it work?:
I have patched this by adding
video=visual.MovieStim(win=win)
in a “Begin Exp” section of a Code Component in my Builder task. Initializing an empty/default Movie component this way at the beginning of the experiment allows the movie Routine to start, and then the actual Movie Component settings I have set in its Builder panel get set inside the Routine and the video appears to behave normally.
My band-aid seems to work but I wanted to flag this in case it can be patched in a longer-term fashion!