Ensure equal number of trials across conditions but items are randomly combined

OS (e.g. Win10): Big Sur (v 11.6)
PsychoPy version (e.g. 1.84.x): 2022.2.3
Standard Standalone? (y/n) If not then what?: Yes
What are you trying to achieve?: 12 trials of each condition (PleasantC, UnpleasantC, PleasantI, UnpleasantI). Within each condition, the word and image are randomly chosen from a set of PleasantWords, UnpleasantWords, PleasantImage and UnpleasantImage.

What did you try to make it work?: I’ve already created a routine with all the necessary elements.

I have also created a xlsx file (screenshot below).

I can pipe in the $Pictures variable in the Image component and the $Words in the text component.

What specifically went wrong when you tried that?: This set up doesn’t ensure that each type of condition only has 12 trials. Essentially, there are two categories of Words (Pleasant and Unpleasant) and similarly for Pictures (Pleasant and Unpleasant). How can I make sure there are 12 trials of each combination? (i.e. PleasantC = Pleasant word + Pleasant picture; PleasantI = Pleasant word + unpleasant picture; UnpleasantC = Unpleasant word + Unpleasant picture; UnpleasantI = Unpleasant word + Pleasant picture). The words and images are randomly combined together within each trial.

This task is similar to the Implicit Association Test, if that helps. Would appreciate any leads. Thank you!!

Hi @jozz, I think the easiest way would be to have 4 arrays defined at the beginning of the experiment containing your unpleasant and pleasant word and picture stimuli (e.g., PlesantP = ["flower1.jpg", "flower2.jpg, ...]). If it’s important to you, you could also read your .xlsx file to get your columns into these arrays, but that would be some extra steps.

Then you could have a conditions file (xlsx) that specifies the condition for each trial (12 x PleasantC, 12 x PleasantI, …). In the beginning of each trial you could then say something like

if condition == "PleasantC:
    stimulus1 = random.choice(PleasantW)
    stimulus2 = random.choice(PleasantP)

to randomly select two stimuli matching the condition.

Hope that helps!

Thank you so much!