Hi everyone!
I’m asking for help with my code that doesn’t work despite all my reseach and testing. In my experiment, I have to display simultaneously 1 image and 1 word on the screen in such a way that images and words are randomly associated at each trial and that images and words stay correctly linked with their emotional valence in my output data file. The experiment: psycho_essai_1_images - Copie.psyexp (14.4 KB)
The problem:
When I run my experiment, the window closes immediately and Psychopy sends me this error message (see below). I have compiled my script and this error appears when psychopy “update component parameters for each repeat”. It may refer to the variable that I have used do indicate the image to be displayed in the Image Component ($imageLat[$imageLat_order[$cur_imageLat]]
) but, if it’s right, I don’t understand why because this way of indictating variables in Builder Components had worked perfectly in my last testing (with colors and words). Maybe a mistake in the code?
Traceback (most recent call last):
File "C:\Users\roman\Desktop\essai_image_psycho\psycho_essai_1_images - Copie_lastrun.py", line 304, in <module>
image_lateralisation.setImage(imageLat[imageLat_order[cur_imageLat]])
TypeError: list indices must be integers or slices, not list
##### Experiment ended. #####
The code:
All variables have been stored in an Excel file containing images (path) and words to display and the emotional valence of each image and each word.
To import my file and load my variables, I have used two Code Components like this:
import xlrd, random
random.seed()
#I create an object to load my file
in_file = 'essai_image_1.xlsx'
#I define the number of items for the experiment
num_items = 6
#I start to increment the counter of my trials
cur_imageLat = 0
cur_mot = 0
#I open and read my file and select the sheet
inbook = xlrd.open_workbook(in_file)
insheet = inbook.sheet_by_index(0)
#I create my empty lists
imageLat = [] #list that will contain images to display
valence_image = []
mot = [] #list that will contain words to display
valence_mot = []
#I fill my lists
for rowx in range(1, num_items+1):
row = insheet.row_values(rowx)
imageLat.append(row[0])
valence_image.append(row[1])
mot.append(row[2])
valence_mot.append(row[3])
#I create two empty lists to group and randomize together imageLat+valence_image, mot+valence_mot
mot_order = []
imageLat_order = []
mot_order.append(mot)
mot_order.append(valence_mot)#here this list contains mot and valence_mot
imageLat_order.append(imageLat)
imageLat_order.append(valence_image)#here this list contains imageLat and valence_image
random.shuffle(mot_order)
random.shuffle(imageLat_order)
#At the end of the test routine, I log my data and increment mot and imageLat counters
thisExp.addData('image_later', imageLat[imageLat_order[cur_imageLat]])
thisExp.addData('valence_image', valence_image[imageLat_order[cur_imageLat]])
thisExp.addData('mot', mot[mot_order[cur_mot]])
thisExp.addData('valence_mot', valence_mot[mot_order[cur_mot]])
cur_imageLat = cur_imageLat+1
cur_mot = cur_mot+1
Then, I have used an Image Component to configure the display of images (size, position…) and I have put $imageLat[$imageLat_order[$cur_imageLat]]
to indicate the image to be displayed. And I have used a Text Component to configure the display of words and I have put $mot[$mot_order[$cur_mot]]
to indicate the word to be displayed.
As I say previously, I don’t understand the error message. Maybe it’s because I have made other mistakes in my code, especially in the way I process images (no window in my code, no .draw()
for images and words because I thought it was treated by the Builder Components).
If someone has any suggestions, I would be very grateful!
Romane.