psychopy.org | Reference | Downloads | Github

Randomly selecting different parameters per iteration of a routine

I’m using…
Windows 10
PsychoPy version 1.82.01

Current Setup. I have an experiment in which a subject is presented a set of overturned cards and one card is subsequently flipped over with each button press they make. Thus, for each button press a new card is flipped over while all other cards from the previous trials remain the same (e.g., all other overturned cards remained overturned, all other ‘flipped over’ cards remain so).

To go about this, I have a routine titled ‘Deck’ with an image, deckImage, and keyboard response in addition to a loop called deckLoop around the routine. deckImage calls a parameter from an excel file called D1 in which there are 16 images (conditions). Each of the images are presented sequential order to accomplish the task described above (i.e., image 1 has all cards overturned, image 2 has Card X ‘flipped over’ and the rest remain overturned, image 3 has Card Y and Card X ‘flipped’ while the rest remain overturned, and so forth).

Problem. I want to use multiple decks throughout the course of experiment, but I don’t want to create a new routine for each one. What I’ve tried to do is create a second parameter in my excel file called D2 with a different set of images (different order of cards being flipped), and tried to hack the coder to randomly pick between the two. The ultimate goal is to add several more decks. So essentially, I want the image to randomly pick between one of X number of parameters, go through all the conditions in the parameter, then loop around and randomly pick again, and so on until the desired number of loops are completed.

My (Failed) Attempt at Fixing This. I’ve tried to hack this by creating a list with all the parameters and conditions (e.g., conditionList = [D1, D2, D3], first initialized as an empty list), and then randomly selecting from that list (using random.choice(conditionList); I imported random at the beginning of the experiment) and setting the result to be equal to another variable (let’s say ‘thisDeck’, also initialized at the beginning of the experiment). I then go into coder view and replace ‘deckImage.setImage(D1)’ with 'deckImage.setImage(thisDeck).
As it turns out, it sorta works. The program goes down the list of images, but doesn’t ‘stay’ in one parameter. That is, for the second trial, it might select image 2 from D1 but then select image 3 from D3 on the next trial.

Any ideas on how to get around this? I’m convinced it’s a straightforward fix, but I’m relatively new to coding in general so I’m a bit stuck. I apologize for any lack of clarity and am happy to further elaborate.

Thanks in advance for the help!

Joao

Hi Joao,

I’m struggling to understand this a bit, but my main recommendation would be to rethink the way you are using images. It would be better if you had 17 image files: one representing an overturned card, and the other 16 representing each individual flipped card.

Then on each trial, you would draw the stimuli according to whatever card is supposed to be overturned on that trial. i.e. initially draw the overturned image 16 times in a grid. Then draw it 15 times, with card x1 flipped. On the next trial, draw the upturned image 14 times, with cards x1 and x2 overturned, and so on.

i.e. shifting to creating the images programmatically rather than as fixed bitmaps will give you much more flexibility. If that’s a route you want to pursue, let us know.

Michael

Hi Michael,

Thank you for your super speedy reply!

I actually found this right after making my post and that actually helped me figure it out (apologies for not having looked through the board more thoroughly before writing the novel sitting just above us).

Following @lindeloev’s suggestion, I created a conditions file for each deck. Then, I created a ‘master’ conditions file with all my other separate deck conditions files as conditions themselves under a parameter called, say, ‘deckList’. Next, I added an outer loop and had it reference the master conditions file. In the inner loop, I set the field for the conditions file to $deckList. It worked so yay!

I’m happy to share a link to the OSF page where the task will be made publicly available once the project I’m using it for is up and running.

Regards,
Joao

1 Like