# Getting correct response from mouse click

**URL:** <https://discourse.psychopy.org/t/getting-correct-response-from-mouse-click/5225>\
**Category:** Builder\
**Created:** [September 4, 2018, 7:52am UTC](https://discourse.psychopy.org/t/getting-correct-response-from-mouse-click/5225 "2018-09-04T07:52:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omidrezaa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/omidrezaa/32/6105_2.png) [@Omidrezaa](https://discourse.psychopy.org/u/Omidrezaa)\
**Post date:** [September 4, 2018, 7:52am UTC](https://discourse.psychopy.org/t/getting-correct-response-from-mouse-click/5225/1 "2018-09-04T07:52:16Z")

</div>

Hi. I think this question has already asked but I could not solve it by looking at the similar subjects.

I want to simply ask participants whether they have seen a word in the previous trials. So, I created a routine, a text which set to be the words and two rectangles below it (yesBox and noBox). Then I created a mouse (mouseMemory):

 ![test](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/c/4c4e5196633f4a5b481eadb69ff21416c2c1adcd.png)  
What I want is to add the correct or wrong response of the participants to the output. So, I wrote the code below:

```auto
#Begin Experiment tab

#10 words that have been presented in the previous section
existWords = [“hammers”, “cats”, “skyscrapers”, “racehorses”, “politicians”, “reptiles”,“Volvos”, “dollars”,“eucalyptus”]

memoryCorrect = 0

#End Routine tab

if mouseMemory.isPressedIn(yesBox):
    if words in existWords:
        memoryCorrect = 1
    else:
        memoryCorrect = 0

if mouseMemory.isPressedIn(noBox):
    if words in existWords:
        memoryCorrect = 0
    else:
        memoryCorrect = 1

thisExp.addData (“memoryCorrect”, memoryCorrect)

```

But in my output file, in the memortCorrect column, I always have 0 in all rows. I would appreciate any help.

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [September 4, 2018, 9:25am UTC](https://discourse.psychopy.org/t/getting-correct-response-from-mouse-click/5225/2 "2018-09-04T09:25:52Z")

</div>

Hi @Omidrezaa, to solve your problem it would be useful to see the output of words:

Add the following under

```auto
if mouseMemory.isPressedIn(yesBox):
    print("Yes selection: {}".format(words))

```

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [September 4, 2018, 9:07pm UTC](https://discourse.psychopy.org/t/getting-correct-response-from-mouse-click/5225/3 "2018-09-04T21:07:21Z")

</div>

Also specify when this code is run. If on every frame, then values could be overwritten with 0 whenever the button is released. If at the end of the routine, then maybe the button isn’t pressed at that point, and so on.

---

<div class="post-metadata">

**Author:** ![Omidrezaa](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/omidrezaa/32/6105_2.png) [@Omidrezaa](https://discourse.psychopy.org/u/Omidrezaa)\
**Post date:** [September 5, 2018, 12:39am UTC](https://discourse.psychopy.org/t/getting-correct-response-from-mouse-click/5225/4 "2018-09-05T00:39:05Z")

</div>

Hi @dvbridges and @Michael.

I edited my previous post to specify that where I wrote those codes (at the end routine).

David- I did not receive any outcomes when I run your codes in the coder menu. However, when I used the codes below, everything was fine. Thus, I think the problem is related to the mouse press:

```auto
if words in existWords:
    memoryCorrect = 1
else:
    memoryCorrect = 0
thisExp.addData ("memoryCorrect", memoryCorrect)

```

This is the output file with the codes of the previous post. I highlighted the added column:

 ![output](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/c/ecac626969b68da70255390d3f565359d13f9db8.png)
