# Has the correct image been clicked on?

**URL:** <https://discourse.psychopy.org/t/has-the-correct-image-been-clicked-on/1713>\
**Category:** Builder\
**Created:** [January 5, 2017, 8:25pm UTC](https://discourse.psychopy.org/t/has-the-correct-image-been-clicked-on/1713 "2017-01-05T20:25:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Melanie](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Melanie](https://discourse.psychopy.org/u/Melanie)\
**Post date:** [January 5, 2017, 8:25pm UTC](https://discourse.psychopy.org/t/has-the-correct-image-been-clicked-on/1713/1 "2017-01-05T20:25:43Z")

</div>

**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](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/1X/c985ead86fd7fadfd49ea30278d0595bc34d9cf8.psyexp) (12.7 KB)  
[PsychoPy2 Test.xlsx](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/1X/94bedf0ef59ebee639510fd079457978000f2d93.xlsx) (8.4 KB)

---

<div class="post-metadata">

**Author:** ![lindeloev](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/lindeloev/32/15_2.png) [@lindeloev](https://discourse.psychopy.org/u/lindeloev)\
**Post date:** [January 5, 2017, 10:23pm UTC](https://discourse.psychopy.org/t/has-the-correct-image-been-clicked-on/1713/2 "2017-01-05T22:23:45Z")

</div>

A few things to try:

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

2. In case `corrAns` is the image filename and you really meant to do

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

---

<div class="post-metadata">

**Author:** ![Melanie](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Melanie](https://discourse.psychopy.org/u/Melanie)\
**Post date:** [January 5, 2017, 11:12pm UTC](https://discourse.psychopy.org/t/has-the-correct-image-been-clicked-on/1713/3 "2017-01-05T23:12:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kuppuslp](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kuppuslp](https://discourse.psychopy.org/u/kuppuslp)\
**Post date:** [January 13, 2018, 5:23pm UTC](https://discourse.psychopy.org/t/has-the-correct-image-been-clicked-on/1713/4 "2018-01-13T17:23:11Z")

</div>

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
