| Reference | Downloads | Github

Shuffle stimuli within routine



If this template helps then use it. If not then just delete and start from scratch.

OS: Win10
PsychoPy version: 1.78.00
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I am trying to create a block-design experiment for fMRI.
There are 8 conditions, and each condition is supposed to repeat 4 times, thus resulting in a total of 32 blocks. The order of block presentation is pre-determined. Each block contains the same 5 pictures, whose presentation I want to shuffle within block.
What did you try to make it work?:
Initially I tried creating nested loops but it got too complicated. Realizing that there is a small amount of blocks (32) and a fixed order, I decided to create only one condition file in which each row represents a block. So, the condition’s .xlsx looks like this:

blockType Pic 1 Pic 2 Pic 3 Pic 4 Pic 5
a.png Pic 1.png Pic 2.png Pic 3.png Pic 4.png Pic 5.png
b.png Pic 6.png Pic 7.png Pic 8.png Pic 9 .png Pic 10.png

Currently this is set up in one routine. An image describing the block type is presented for 2.5 seconds, followed by the 5 pictures which are presented for 3 seconds (i.e. pic 1 for 3s, followed by pic 2 for 3s etc.). The loop type is sequential, as the " blocks’ " order is fixed.
Now, I wish to shuffle the presentation of pictures within each “block” (i.e. routine), e.g.:

blockType Pic 1 Pic 2 Pic 3 Pic 4 Pic 5
a.png Pic 2.png Pic 5.png Pic 3.png Pic 1.png Pic 4.png
b.png Pic 10.png Pic 8.png Pic 6.png Pic 9 .png Pic 7.png

Additionally, a key-response is presented simultaneously with each picture, as participants are required to rate the pictures.

What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.


Stop fighting it and go back to having nested loops. That way you can separate out the sequential and randomised factors as required instead of trying to somehow meld them together. It might seem complicated but, although there is a way of achieving what you are trying to do currently, it will actually be much more complicated than working with Builder’s provided loop facilities.

Your outer loop conditions file will look like this:

blockType  conditionFile
a.png      pic_1-5.csv
b.png      pic_6-10.csv

pic_1-5.csv will look like this:


and similarly for pic_6-10.csv

You need two routines. The first will show just the block type image, using the $blockType variable from the outer loop. The outer loop is set to be sequential.

The second routine also has just one image component, controlled by the $imageName variable from the inner loop. The inner loop encompasses just this second routine and is set to be random. The name of the conditions file is the $conditionFile variable from the outer loop.

So for every iteration of the outer loop, the first routine will be shown once, displaying either a.png or b.png, and the second routine will run five times, showing the randomly assigned images from either set.


Works perfectly. Thanks!