psychopy.org | Reference | Downloads | Github

Using code to choose one of two images

Hello,

What are you trying to achieve?:

I have two variables (context_sad, context_neu) that include paths to images:

I want that in each trial one row will be selected randomly, and then, according to some count (using an index), one of the two variables (context_sad or context_neu) will be selected, so that only one image will be displayed.

What did you try to make it work?:

I have created a code.
At the before experiment, I created the indexes and a variable called context_list:

then, at the begin routine, I created the following code:

Of course, I have also created a loop that refers to the excel file in which the variables are written.

this is how it looks like when I convert the builder into a code:

But it doesn’t work. I think I have a syntax error and I am not sure what it is.

What specifically went wrong when you tried that?:
There is no error. The experiment just ends with no image displaying.

Does anyone have an idea how to write it better or what is wrong?
Thank you very much,
Lior

It looks like you’re setting the image to be the string 'context_list' rather than the value of that variable - what happens when you remove the quotation marks?

Thank you for the help!
I think it solved my problem.