Issue with blocks and looping, selecting images from 2 files randomly

OS (e.g. Win11):
PsychoPy version (v2021.2.3):

Trying to show images of faces and objects in two separate blocks, and have it loop 5 times. So the experiment would start with a block of faces, then a block of objects, then a block of faces, and so on until each block is shown 5 times. I also need the images to be selected randomly with repitition for an n-back task.

I’ve used a bit of code and a few excel files to try to make it work. I’ve hit a few errors but have worked through them a few times, I’ve gotten to the point that I have it working to loop through each block one time, but then it stops and when I set nReps to 5 in either my inner or outter loop I get an error.


Here is the code that I used:

from numpy.random import choice

blocks = [‘facestimlocalizer.xlsx’,‘objectstimlocalizer.xlsx’]
shuffle(blocks)

In the select rows for the trial handler you’ll see that I have it set to 3 right now, that’s just for testing purposes to cut down the time it takes to run the blocks.

This is the error message I get:

IndexError: list index out of range

Experiment ended.

Does anyone know what I may be doing wrong here or how I could try to fix this? Please let me know if anything is unclear. Thank you!

I have a similar problem. Basically the outer loop selects a blocks_file that contains filenames for blocks, and the inner loop references the column in blocks_file that should read which file to pick. But it won’t work.

When are you getting the out of range error? If you use pop then your list of files will be empty after 3 loops.