Randomizing a Combination of visual and olfactory stimulation

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x): v2022.1.2
Standard Standalone? (y/n) If not then what?: yes
What are you trying to achieve?:

Hey everyone,

I am currently trying to build my first experiment in PsychoPy (also my first exp. ever), so I am very new to this.
During the fMRI Experiment, participants are presented with a combination of a visual and an olfactory stimulus, which they then rate on various scales. There are 10 different visual stimuli and 4 olfactory conditions, and each combination should be presented twice in total, in a random order.

I have to ensure that participants are not presented with the same picture twice/multiple times in a row, only with a varying olfactory condition (so picture 1 with odour a and then picture 1 with odour b, right after the other).

What did you try to make it work?:
In Builder, i created a loop which loops over the Routines for stimulus presentation and the subsequent ratings, using an excel file to specifiy the visual-odour combination for the next run (type: random, nr. repetitions 2). The file contains 2 colums, one specifying the image file and one the odour condition (which will have to be fed into some code for the computerized olfactometer later), and all rows to include every possible combination once.
With this i could ensure that a specific combination is not repeated directly, but only after all combinations have been presented once.

What specifically went wrong when you tried that?:
With this method I can not rule out, that the same picture might be chosen twice in a row with a different olfactory cue.
I would appreciate some help and thank you for your time and apologize, if I overlooked something!

This is the closes thing I can see to what you want to do that may help. I am not brilliant with the code components though, but this looks close enough.

Could you please link your code or how you overcame this? I’m doing something very similar and am completely stuck!

Hi,
I ended up creating one file per participant containing the order of the stimuli. Since I included the variables described above (10x4x2) I ended up with a list of 80 entries (1 picture-olfactory -combination per entry). I pseudorandomized it adhering to my requirement of no picture twice in a row. Doing this for the estimated nr. of participants I just had to make sure that all lists are unique.
I numbered them in the file name and give Psychopy the correct number per participant at the beginning of each trial.
I dont think something like this is possible with the randomzie functions in Psychopy itself. You will always have to create the order in advance.
Hope that helps