Help with coding targets and distractors

My experiment will show participants 10 pictures one at a time (1 second each). After a 30 second video, the participants are shown a screen with the 10 they saw originally and 10 new items.

With the help of someone on this forum I was able to do this withmy practice trials. However, now that I ve started building my test trials, I am noticing that the number of pictures shown (Should be 10) is variable, sometimes it only shows 4 pictures and other it shows 8. I have added my code for easy access.

My excel data file shows that 20 images are pulled from my list, but psychopy is not showing the 10 targets.

example.psyexp (23.2 KB)

Hi @sarahnpope, I guess “someone on the forum” cough made a little mistake when helping you. This is a new version that should do what you want, regardless of the number of targets etc.

example_new.psyexp (23.3 KB)
stimuli.xlsx (8.8 KB)
jpg|500x500

1 Like

Do you know why the image array might still be showing after the presentation routine has ended? The array still shows after that routine and on the test instruction routine

You should add

for image_stim in image_array:
    image_stim.setAutoDraw(False)

to the “End routine” tab.

So, I need there to be 3 loops of the 20 image array (10 targets and 10 distractors). Will this code allow for randomizing each loop?

Yes, make sure to include the code routine that selects the stimuli inside the loop.

Thanks! The test response array is only showing the target images orginally presented. I tried setting a loop around the response routine with selected rows set to $TargetsAndDistractors (I had this in the presentation loop “Selected rows” but it kept showing 20 pictures instead of 10, so I set that to $Targets)

So you want to present 10 Targets and then present 3 Arrays with the same Targets and different Distractors?

Not quite. I’m wanting 3 blocks of 10 targets presented and a response array of 10 targets and 10 distractors. I am okay with some of the pictures being presented multiple times, I just want them randomly drawn

If you take my example and simply add a loop with 3 repetitions around the whole thing that should work.

The program is giving the following error message:

File “C:\Users\sarah\Desktop\example\example_new_lastrun.py”, line 407, in
ori=0.0, pos= positions[i + len(target_images)], size=(0.15, 0.15),
IndexError: list index out of range
################# Experiment ended with exit code 1 [pid:2560] #################

on the second loop. It is also reusing the same pictures. do we need to reset the lists after the first loop?

Yes, maybe there is some code in “Begin experiment” that you should copy to “Begin routine” so it is part of the loop.

THank you so much!!!

1 Like