OK, insert a loop around the routine that will show the images. Give it a very large nReps
number (like 1000), and don’t connect it to a conditions file.
That routine should have an image component, with the image field set to update every routine, and containing a variable name like $current_image
.
Also insert a keyboard component, set to force the end of the routine with a single keypress, and with valid choices specified (e.g. 'left', 'right', 'space'
)
Insert a code component, which must be above the image component. In the “begin routine” tab, put something like this:
# set the starting value for the image number:
if your_loop_name.thisN == 0:
img_num = 1
# adjust as required:
current_image = f'testStim/{bID}_{prefix}{img_num}.png'
Then in the “End routine” tab, something like this:
if your_keyboard_component.keys == 'left':
img_num = max(1, img_num - 1)
elif your_keyboard_component.keys == 'right':
img_num = min(61, img_num + 1)
else: # must be 'space'
your_loop_name.finished = True # end the process
thisExp.addData('chosen_image', img_num) # record the answer
I’m guessing you currently have a trial loop that controls the other variables you refer to, like prefix
and bID
. So this other loop is nested inside that one, and only surrounds this recall routine, not the preceding ones that showed the initial image and the adaptation stimuli.
You might also need to deselect the “is trials” setting on this inner loop, as otherwise, you will get a row of data recorded for every keypress, rather than just one per trial. Do be careful to check that the data file is structured as you need it.