Selecting images on screen using mouse in builder view

You will want something like this in the Each frame tab of a code component:

# cycle through the stimulus components by name:
for stimulus in [ Q, C1, C2, C3, C4, C5, C6]:

    # check if the mouse is pressed within the current one:
    if mouse.isPressedIn(stimulus):

        # Yes, so store the reaction time in the data:
        thisExp.addData('RT', t)

        # check if the stimulus' image filename matches the correct answer:
        if stimulus.image == eval(corrAns):
             thisExp.addData('correct', 'True')
        else:
             thisExp.addData('correct', 'False')

        # end the trial once done here:
        continueRoutine = False

        # stop any further checking:
        break

The eval(corrAns) is necessary because your corrAns variable doesn’t directly contain the name of the image file but instead the name of the variable which contains that image filename, and so that string needs to be evaluated to return the contents of the variable. If your corrAns variable contained the name of the image file directly (e.g. A2C1.jpg), then you could simply do if stimulus.image == corrAns:

1 Like