psychopy.org | Reference | Downloads | Github

Getting correct response from mouse click

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):


What I want is to add the correct or wrong response of the participants to the output. So, I wrote the code below:

#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.

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

Add the following under

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

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.

2 Likes

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:

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: