Is it possible to randomize two different sets of stimuli with different numbers?

My task pairs words and images.

I have four words, and eight images.

On every trial a person should get a random word along with a random image.

The twist is that I would like to go through all four words once, and only then present each word a second time. So, for example, the words presented on each trial might look like this:

T1: cat
T2: dog
T3: tree
T4: sky
T5: dog
T6: sky
T7: cat
T8: tree

How I’ve thought to do this would be to just create an object that is the four words randomized once, and then attached to the four words randomized again. And then to call from this object on each trial. In terms of images, I figure I will just use a condition file.

Does this make sense? Could anyone point me to a resource for creating a list of items on the go in PsychoPy?

I do this kind of thing quite often. Have a look at my Independent Randomisation online demo. You could sent the first loop up with nReps = 2 to create the list you want.

Thanks for this!

I’m curious if there is a way to do it without even needing to use an Excel file?

I’m more familiar with R, so I’ll use that langauge, but I wonder if you could do something like this:

stim ← c(“cat”, “dog”, “tree”, “sky”) #create a vector of the four target items

stim1 ← shuffle(stim) #shuffle their order; that isn’t an R function exactly, but just to show what I’m thinking

stim2 ← shuffle(stim) #do it again

finalstim ← cbind(stim1, stim2) #combine them into a list of eight, and then load the stimuli on each trial from “finalstim”

Is something like this possible?

tempStims = ["cat", "dog", "tree", "sky"]
stims = ["cat", "dog", "tree", "sky"]

for Idx in range(len(tempStims): # or "in range(4)"

Then you can either use stims[trials.thisN] or finalstim = stims.pop() which will take the final item from the list and remove it in the process.

In Python you can combine lists more elegantly than I have here (possibly stims = stims + tempStims) but it doesn’t work online.

1 Like

Thank you!!!

I’ve added finalstim = stims.pop() to the end.

In my trial I have set Text to equal $finaltim. I also have a loop that repeats eight times.

However, it shows the same stimulus for each trial. I’ve tried both “constant” and “set every repeat”. Do you know what might be happening?

It should be $finalstim (check your spelling) set every repeat.

finalstim = stims.pop() should be in Begin Routine in a code component above the text component. In general, put code components first in a routine (unless you have a specific reason to do otherwise).

Thanks once again! Is there a way to tip you?? You’re always so helpful.

I got it to work by using $stims[trials.thisN] and including the code in a separate Routine that comes first.

You’re very welcome. I’m glad the code is working for you.

I’ve been helping people as a hobby since lockdown started (because I needed to learn myself and have become an expert on the quirks of moving PsychoPy experiments online using the auto translate tool). Today is my first official day of employment as a part-time Science Officer for Open Science Tools.

If you’d like to “buy me a coffee” as a token of appreciation, then please could you use this site:

Done! Thanks again!

1 Like

Me again…

This was working nicely on my computer, but when I tried to run it on Pavlovia I got the following error:

Unfortunately we encountered the following error:

  • when setting the image of ImageStim: image
  • when getting the value of resource: Pair1_RL_G.png
  • unknown resource

Try to run the experiment again. If the error persists, contact the experiment designer.

Note that this is for the images I’m presenting, which are set up in a simpler way than the words you helped me with above. There are simply eight images, and they get shuffled at the start of the experiment like this:

images = ["Pair2_RL_G.png", "Pair2_RL_Onew.png", 
"Pair1_SL_Onew.png", "Pair2_SL_Onew.png",
"Pair1_RL_G.png", "Pair1_RL_Onew.png", 
"Pair1_SL_G.png", "Pair2_SL_G.png"]

I wonder if there’s something I need to do differently because it is now being presented on Pavlovia?

Have you attached the images via Experiment Settings / Online ?

1 Like

I had not. :slight_smile: It works now. Thank you!!

I have a follow up for this experiment. It is working well, but the output doesn’t list the stimuli that were presented on a given trial. Is there a way to have it do this?

For reference, I randomize the list of images at the start of the experiment like this:

images = ["Pair2_RL_G.png", "Pair2_RL_Onew.png", 
"Pair1_SL_Onew.png", "Pair2_SL_Onew.png",
"Pair1_RL_G.png", "Pair1_RL_Onew.png", 
"Pair1_SL_G.png", "Pair2_SL_G.png"]

And then on a trial I call a certain image like this:


But is there a way to have the output include which image was shown on a given trial?

1 Like

Thank you! I’ve added a code component to the trial itself, and added this code to the Begin Routine section. it looks like it works perfectly!

1 Like