I am designing an experiment where a selection of 10 different images are displayed on the screen for a small amount of time (presentation routine). The participant then has to make a decision about which image represented the most common image that they saw (decision routine).
I have the presentation routine working fine.
During the decision routine though, I would like it so that the participant can actively change the image that is displayed on the screen using a keypress. So, an image would appear after the presentation routine (randomly selected from the 10 images), then when they press e.g. the left key, a different image is presented. Once they have the desired image on the screen, they press the return key and the image choice is logged and the next trial begins in the loop.
I have been working with the BART example script but continually get stuck with my modifications.
Is this possible to do? Any guidance would be much appreciated.
Hi,
If Iâm understanding your design, then this should be quite simple to implement using a code element. Youâd want to specify your image names through a variable name: so put $imageVariable or some such name in the âImageâ field of the relevant image component in your routine. You also need to set this field to âset every frameâ.
Now you just need to update the image name via code. So create a code component and in the âEach frameâ tab (so the code runs every frame) then just check whether a key has been pressed and update the variable holding your image name appropriately and the image will change:
Hereâs an example of something similar I did recently that updates the image every frame (to create a running clock). I increment the counter elsewhere in the script (via another code element) and included a keyboard element in the Routine called âbuttonPressButtonâ and then inserted the following code in the âEach Frameâ tab of the Routineâs code element:
This will update the variable âimageVariableâ (so you get filenames like IMG_1.png, IMG_2.png, IMG_3.pngâŚ) This is picked up by the image routine which displays the relevant image file.
Hi J,
thanks for your post about your willingness to share. This is very close to what I am attempting to do at the moment and I would appreciate seeing the code if you are still happy to share.
Warm regards,
Kirsten
Dear James,
I cannot thank you enough for sharing this! You are a lifesaver. In particular because you even have the âlimitsâ of the image in there too. My experiment only varies on one dimension (pictures of food at various depth disparities). So I am now going through and simplifying your example. (I too will share with anyone interested).
I am only struggling with saving the data.
In your code snippet in setImage_2/endRoutine you have the trials.addData commands (see below). When I uncomment them I get:
NameError: name âtrialsâ is not defined.
However, when I green the addData commands out then tick the âis trialsâ box in the Practice properties loop I get data in the csv filew_2018_Jun_08_2008.csv (1.5 KB)
. Is this giving me the same as what the addData lines would have given me?
Do you think there is any problem with using the âis trialsâ checkbox? Is your setup this way because it was practice trials?
All I really want is the name or index of the image file they choose before pressing enter.
Again, I am very thankful for you sharing this. A huge help.
Yes, if you would like to save the image choice information (i.e. which image file is being shown before the participant presses âenterâ), uncomment the lines in endRoutine and tick the âis trialsâ box in the âPracticeâ properties loop.
Yes again, I originally had a few practice trials in my full experiment and based the example on those trials.
In the code component setImage_2/Each frame: choice_trial creates a variable with all the information about the selected image i.e. size and orientation choice_trial_size just the âsizeâ part of the image choice_trial_view just the âorientationâ part
When these are saved as data, they will simply be numeric variables, e.g. choice_trial would be 15, if the participant chose a body size = 1 and orientation = 5, as the image file would be 1_5.png
Hope this helps, but feel free to ask if anything is unclear
Thank you for further describing those variable definitions. Makes sense.
I have uncommented the addData lines, ticked the Is trials box, but unfortunately I am still getting this error
File ââŚImage_change_example_lastrun.pyâ, line 350, in
trials.addData(âimgChoice1â, imgChoice1)
NameError: name âtrialsâ is not defined
Ah, just got why this is coming up with an error, when you uncomment in the âEnd Routineâ part, the trials.addData is referring to a loop called âtrialsâ but as the loop is called âpracticeâ in the experiment, this causes the error.
Solution - change the name of the âpracticeâ loop to âtrialsâ, making sure the âis trialsâ box is still ticked.
Iâll update the linked example, to avoid future issues.
Ah Ha! Sorted. I had to change the name of the loop to âtrialsâ in addition to uncommenting and ticking the âis trialsâ box. So the loop is no longer âPracticeâ, but âtrialsâ instead. Now I have an a beautiful csv file including those important choice variables.
So for other people reading this, to make the save variables work-
I downloaded the linked files
uncommented the green addData lines in setImage_2/endRoutine #trials.addData(âimgChoice1â, imgChoice1) #trials.addData(âchoice_trialâ, choice_trial) #trials.addData(âchoice_trial_sizeâ, choice_trial_size) #trials.addData(âchoice_trial_viewâ, choice_trial_view)