Has the correct image been clicked on?

OS : Windows10:
PsychoPy version: 1.84
Standard Standalone? (y/n): yes? I’ve not added anything
What are you trying to achieve?

I’ve got help from a couple of the other threads, but I’ve run into a bit of a problem with some of the code I’ve adapted. I’m trying to get it to compare whether the clicked-on image is the response I’ve stated as correct in the Excel file and report it back in the data output; at the moment, it’s always coming back as ‘Not selected’ and I can’t work out why.

I’ve got the following in the ‘each frame’ part of adding code in Builder.

` # cycle through the stimulus components by name:
for stimulus in [ Image1, Image2, Image3, Image4]:

    # 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('selectedAns', 'Answer')

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

        # end the trial once done here:
       while np.any(Mouse.getPressed()):
            pass
            continueRoutine = False

        # stop any further checking:
        break 

        core.wait(0.3)

If anyone can offer any help/advice that would be greatly appreciated, thank you!

Trial 2.psyexp (12.7 KB)
PsychoPy2 Test.xlsx (8.4 KB)

A few things to try:

  1. stimulus.image contains the file name or however you specified the image. Perhaps you mean to do

    if stimulus == eval(corrAns):
    
  2. In case corrAns is the image filename and you really meant to do

    of stimulus.image == corrAns:
    

    then check that stimulus.image is indeed equal to your corrAns column. We often see that one includes a path whereas the other does not. Sometimes it’s just a misspelling or a capitalized letter that’s causing two strings not to be equal Check this by printing the value of these variables just before the if…eval line:

    print 'stimulus.image =', stimulus.image
    print 'corrAns =', corrAns
    

    naturally, if that is the source of the “Not Selected” line never being run, just correct the error :slight_smile:

  3. I think you want the continueRoutine = False just after the while loop - not inside it. But this should not cause the problem here.

Thanks! Yeah, it was the stimulus/image and eval/corrAns situation that was causing problems, but looks like I’ve got it sorted now.

The continueRoutine = False thing doesn’t seem to be causing any issues at the moment, and I’m a bit scared of accidentally breaking everything if I change something, but I’ll definitely bear that in mind if any other problems arise.

This is more relevant here.

I don’t have a column called ‘CorrAns’ in my condition file. Rather I want to check if the mouse was clicked on ‘Image_3’ . If so give a score of ‘1’, otherwise ‘5’. In my response sheet I always get 5 under the column score(added ‘score=0’ under ‘Begin Experiment’), even if I click on image_3. This simply means the line ‘if stimulus.image==image_3:’ is never happening.

My ‘Each Frame’ of code component looks like this

for stimulus in [image_3,image_4]:#the name of image components

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

        thisExp.addData('RT', t)
        # check if the stimulus' image filename matches the correct answer:
        if stimulus.image==image_3:
             thisExp.addData('score', 1)
        else:
             thisExp.addData('score', 5)

        continueRoutine = False 

How do I rephrase this line ’ if stimulus.image==image_3:’ so I can pick the mouse click on actual image component?

Thanks in advance