| Reference | Downloads | Github

Allow participant to cycle through a set of images


I’m new to PsychoPy, trying to “translate” a visual-adaptation experiment I had just finished coding in MATLAB before Covid hit

For the reponse I need participants to cycle through a set of 61 consecutive images and choose one (preferably using the mouse if possible), but I’m realising the builder isn’t really designed to go forwards and backwards in this manner, and I can’t see another way besides a conditions file to set the image for display.

Is there a way I can bodge this in the builder view? or will I need to code this manually?

You can do this in Builder, but it will likely be best to avoid using a conditions file and instead use some custom code to handle image allocation.

Can you describe the trial procedure in more detail?

Participants are briefly presented with an image of a computer-generated identity, followed by some adapation stimuli designed to shift the percept. Then they are asked to recall what the person looked like - the series of images varies a single dimension of the identity’s appearance from one extreme to the other, my DV is which image they choose and how far this is from the original image

I’ve got as far as concatenating a string for the path and filename of the image each frame: current_image = [‘testStim/’ + bID + ‘_’ + prefix + currentPos + ‘.png’]

My thinking is participant responses can increase/decrease currentPos from 1-61, and then I can store that as the reponse at the end of each trial, although I can’t see how to update the variable with keyboard/mouse input

Am I along the right lines?

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.

Thanks, that’s just what I needed!