Hi Aaron,
> Each trial is exactly the same in terms of layout, so you're right, it doesn't make sense to create 20 routines. But, I'm not sure how to get each repetition of the routine to draw from a discrete set of stimuli and not to draw from it again (for each participant).
That detailed description makes it easier to figure out what to do. I'll suggest a way, but it may not be the best way. For your first experience with PsychoPy, you've chosen a more complicated design than it is built for "out of the box", but it is flexible enough that we can tweak things to accommodate. What complicates matters is the selection of a random audio stimulus from a variable number of trial-specific stimuli.
In essence, though, I think you need just need one loop, and a csv/xlsx conditions file of just 20 rows.
You will have two columns for the images, and a column for the audio. The tricky thing is that the number of audio files can vary from trial to trial, so we are going to need to squeeze them into a single column. They'll need to have a special format, as follows:
image_A, image_B, audio
cat.png, dog.png, "[1.wav, 2.wav, 3.wav]"
bat.png, rat.png, "[4.wav, 5.wav, 6.wav, 7.wav]"
i.e. the audio cells need to be surrounded by quotes as they contain commas (which otherwise would be used to separate cells). They also need square brackets, as these can be used to indicate a "list" object in Python.
image_A and image_B can be used as standard Builder variables, but "audio" will need some extra steps to become usable for you.
Again, in a code component, in the "Begin Routine" tab, put this (it will interpret the string of characters into actual Python code):
audio = audio[1:-1] # we need to strip off the quotes at each end of the string
audio = eval(audio) # evaluate the string, making audio into a list of filenames
shuffle(audio) # randomise that list
audio = audio.pop() # just take one item from the original list
Again, make sure this code component is above any sound object.You can then just put "$audio" (no quotes) in the sound component's Sound field.
Lastly, in the "End routine" tab of the Code component, put:
thisExp.addData("SoundFile", audio) # save the chosen filename for this trial.
# not using the name "audio" to label this column, as it may conflict with the original variable?
> If so, this still wouldn't seem to solve the issue of randomizing the trials (in itself).
This is now handled simply by setting the loop to cycle randomly through your 20-row condition file.
> In the datafile, I need to know for each trial:
> 1. what audio file was played
As above.
> 2. what images were shown and on which side
The image names are automatically saved, as they appear in the conditions file.
The side was described in the previous message.
> 3. which key response (of 2) was selected
That should also be stored automatically. See the online Stroop demo for that stuff.
Regards,
Michael