psychopy.org | Reference | Downloads | Github

Randomizing order of videos played within a loop

OS (e.g. Win10): MacOS Mojave 10.14.6
PsychoPy version (e.g. 1.84.x): v3.1.2
Standard Standalone? (y/n) If not then what?: no idea what this means
What are you trying to achieve?:
I have two video clips I need to show and I want the order (so basically which one is shown first) to be random, while still showing both only once. I feel like this is a stupid question but I’ve been trying to find demos online, youtube tutorials, and other resources to find how to do this but I’ve been unsuccessful…

What did you try to make it work?:
I’ve tried nesting randomized loops around both routines while each routine has its own separate loop, only having a loop around both routines (no nesting), using 1 for nResp for loops, using excel sheet variables (ex. $boring_stim) for nResp, etc.

I’ve also tried switching between making the loops random and fullrandom.

I’ve messed around with my excel sheet and it went from looking like this:
boring_stim engaging_stim
1 0
0 1
to just this (since I think I only technically need one variable randomized since I only have two):
boring_stim
1
0

I read somewhere that using 1 in excel runs that portion while using 0 skips it. And since both have to be played once, if the first video happens to be skipped then the 2nd one will play first and then the 1st…or so I thought.

What specifically went wrong when you tried that?:
Each time I tried something new to make it work, it’d usually still run…just not correctly. It either doesn’t run randomly (acts like it’s running sequentially) or for some reason will play randomly but plays each video segment twice instead of once.

Or when I tried playing around with using a variable in nResp it would sometimes say that I didn’t define the variable if I did that it one/two loops but not another.

Here’s a screenshot of the loop I need randomized:
55%20PM

It is simpler than all of this. You only need one routine. In the video stimulus component, put a variable name like this in the “Movie file” field: $movie_filename.

Then your conditions file would look like this:

movie_filename
boring.mov
engaging.mov

(Use your actual filenames of course.)

Then simply set the loop to be random, with nReps of 1, to get a single presentation of each video, in random order across subjects.

1 Like

Thank you so much for your help! I made the changes you suggested however, I keep getting this error message:
filename=movie_filename,
NameError: name ‘movie_filename’ is not defined

Shouldn’t it already be defined since the conditions file in the loop defines it?

Next to the “Movie file” field, set it to update “Every repeat” rather than be “constant”.

The reason for the error: at the moment, I’m guessing you have it set to “constant” which means a single filename will be applied, just once at the very beginning of the experiment. As the loop doesn’t exist at that point, the movie_filename variable is not yet defined.

1 Like

Thank you that helped with that error!

I don’t know why this would happen but now my experiment runs but freezes on the routine I have before the loop and then skips my video loop and all the routines I have after the video stimuli loop and just goes straight to the end screen. Why would this happen? And how would I fix that?

I think it has something to do with my loop because if I remove the videos and condition file it’ll run the experiment without freezing in that spot and continue with the other routines before getting to the end screen. (I have no clue why my video loop would mess up routines that come after it though.)

I appreciate the help so far and, hopefully, you’ll know how to fix this new problem I’m having with it now!

Update: I made a new experiment file and repeated just the video loop to see if it would work and only play each video once. Unfortunately, it runs but the screen is completely blank and no audio plays. No error message either