Hi! So far, I’ve only built experiments in the Builder, but I think what I need now is the coder. So, it’s a simple picture selection task. 2 pictures are displayed on the screen. If the participant chooses one of them, the chosen picture needs to be displayed in the next screen together with a new picture, etc.
I think you can’t design it in the builder. As for the Coder, the way I see it is that in the beginning of the routine I would need to create some variable ‘chosen_pic’, and at the end of the routine I would have to assign the key response that represents a certain picture to this variable.Then I need to somehow tell PsychoPy to show that chosen picture in the next trial together with a new picture from some sort of a list.
Although I have experience in Python, I’m not sure how to build it technically. I’d be glad if you could provide some hints.
In almost all cases I would recommend you use Builder and then add code components to customise, rather than writing in Coder.
Have a look at some of my demos to see how variables can be used in code components and other builder components
You could have ‘left’ for left picture and ‘right’ for right picture as keyboard responses. Then use a code component to set chosen_pic as image1 or image2. Then in Begin Routine, set image1 (or image2) as chosen_pic and the other one as newImage (if this is the name of your column of image names in your spreadsheet).
Hi! Thanks for the answer! Just to clarify, are all images supposed to be listed in one column in the Excel spreadsheet (no matter whether left or right)? And in the builder, would you still have 2 visual components (one for left and one for right)?
Thanks a lot once again! At the moment, I have 2 visual components: image1 and image2. Both are set to take pictures from the column newImage ($newImage). Then I added a code component as you said: in the Begin Routine, I have written:
image1 = chosen_pic
image2 = newImage
Finally, in the End Routine, I have:
if key_resp.keys is 'left':
chosen_pic = image1
if key_resp.keys is 'right':
chosen_pic = image2
Unfortunately, at the moment I see the same pictures displayed both on the left and on the right. When I press either ‘left’ or ‘right’ arrow keys, I proceed to the next trial where identical pictures are shown on both sides. What am I missing?
Traceback (most recent call last):
File “/Users/arminegaribyan/Desktop/Image_test_conditional/exp_file_lastrun.py”, line 131, in
image1.setText(pic1)
NameError: name ‘pic1’ is not defined
Is that because the column name is actually called newImage? If it sounds too abstract, I’m attaching the experiment file with pictures and the Excel sheet (archived). Image_test.zip (252.4 KB)
I managed to make it work, although I had to change a few things. First of all, I was constantly running into wrong path issues for the images, so I had to play around with text. So, that’s what I’ve changed:
Moved the code component to the top of the routine.
In the Begin Experiment tab of the code component, I added chosen_pic = None because the first routine will not have any chosen picture and I was running into errors like chosen_pic is not defined.
Then in the Begin Experiment tab of the code component I added and if statement to account for the absence of the chosen_pic:
Finally, the End Routine tab stays as earlier suggested.
Ideally, there are still a few drawbacks: 1, I start with one of the sides empty, but I’m sure I can fix this by introducing a random picture for one-time use; second, 2. the chosen pictures appear always on the left, so this could be also probably counter-balanced in the future.
I then tested this with visual components and it worked too. Just instead of pic1 = ' ', you need to write pic1 = None, otherwise PsychoPy can’t recognise a picture, it’s just text.
Thanks for the tips @wakecarter , I’m so glad it has been resolved.