Simultaneous presentation of image and word randomization problem

Hello all,

WHAT DO I HAVE?
I have an object image list with 127x6 items. Each object has 6 colors. For instance, I have a car with 6 different colors, a book with 6 different colors, etc. Corresponding to each object image, I have a word list with 6 different color names of corresponding objects. E.g. words “Blue Car”, “Pink Car”, “Green Car”, etc. Participants will be presented with images and words simultaneously on the two sides of the screen.

WHAT DO I WANT?
So, I want to randomly select one image among 6 different colors (e.g. image of Blue Car) and randomly select one of the 6 corresponding word colors (e.g. “Pink Car”).
I do not want to manipulate the object name (e.g. I do not want to see the word “Green Book” while presenting a blue car image).

WHAT DID I DO?
Here is what I have created:
Begin experiment :
curr_item = -1
Begin Routine:
curr_item +=1
word = word_list [curr_item]
image = image_list [curr_item]

#this is for every 6 images and words to match within each other. so that the object name will not be manipulated.
if image == image_list [6xcurr_item: curr_itemx6+6]:
word = word_list[6xcurr_item, curr_itemx6]

THIS METHOD DID NOT WORD
Example: Green Car image matched with “Green Car” word. However, what I want is to shuffle the corresponding word list (e.g. I want it to be possible to see the word “Red Car” or one of the other colors)

Excel sheet (different colored columns represents the same object with different colors-normally they are not colored):

Trial Information:
for image:


for text:
Please ignore the “imagery”

Code components
Begin Routine:


Begin Experiment:

SECOND WAY:
SINCE THIS METHOD DID NOT WORK, I TRIED ANOTHER WAY
Defined every 6 image and word options as 6 columns.

Code for images:

columnChoice = [1,2,3,4,5,6]
shuffle(columnChoice)
thisExp.addData(‘imageN’,columnChoice[0])
if columnChoice == 1:
thisImage = image1
elif columnChoice == 2:
thisImage = image2
elif columnChoice == 3:
thisImage = image3
elif columnChoice == 4:
thisImage = image4
elif columnChoice == 5:
thisImage = image5
elif columnChoice == 6:
thisImage = image6

Code for words:
shuffle(columnChoice)
thisExp.addData(‘wordN’,columnChoice[0])
if columnChoice == 1:
thisWord = word1
elif columnChoice == 2:
thisWord = word2
elif columnChoice == 3:
thisWord = word3
elif columnChoice == 4:
thisWord = word4
elif columnChoice == 5:
thisWord = word5
elif columnChoice == 6:
thisWord = word6

Component information:



Other Codes:

ERROR
** It says that the image1 is not defined. **

  1. How am I going to define image 1? I mean, 6 columns of images so that they can be randomly selected among 6 columns?
    Suggestion was: thisImage = ‘images/’+image6 +’.png’ gave a Syntax Error.

  2. How am I going to do the first option for word?
    thisWord = … ??

I tried defining image1…image6 and word1…word6 as separate empty lists, did not work. I tried to append these all in the image variable, did not work. I tried to append image1, …image6 into image list but did not work either.

I do not have enough coding skills. I would be really appreciated it if you explain it to me step by step.
Thank you.

I recommended that you use thisImage = image1 because you can’t use image as a variable name online.

Don’t use simple terms for variables, since they may already be in use by PsychoPy. Variable names to avoid are: class, core, image, index, Length, list, Object, Number, round, sound, Symbol, t, thisTrial, trials, util, visual.

You will need to put thisImage = ‘’ in Begin Experiment to avoid a thisImage is not defined error.

Try adding

print('thisImage',thisImage) 

at the bottom of the Begin Routine tab of your code component.

This should give some useful output before it crashes.

I would recommend putting the experiment in My Documents instead of Desktop.

I’ve spotted an error in the code I gave you.

Where it says

if columnChoice ==
and
elif columnChoice ==

if should say

if columnChoice[0] ==
and
elif columnChoice[0] ==

otherwise thisWord is never set because a list of 6 items doesn’t equal a single number.

1 Like

Its been almost 10 days since I am struggling with these codes. Thank you so much. It perfectly worked. :pray:

I think it could be about the character in word5. There may be a different way of encoding this. Equally, it might only be a problem for the print statement.

1 Like