Define correct answer for mouse click

Dear all,

In my experiment, I present participants words then ask them to recall from list of 6 words.
I show them a random color e.g. “Blue Phone” word (encode), then they should find the color among 6 options (position is randomized) by clicking on the Blue Phone (retrieve).

There are different routines for encoding and retrieval phases. The .xlsx file has word1, word2,… columns for encoding and mywordlist1x mywordlist2x… for retrieval. color in the word1 always matches with mywordlist1x and the same is the case for the rest of the options. I mean, word1 and mywordlist1x correspond to “Blue Phone”.

This is the part where a random word is selected as Blue among 6 alternatives.

    elif wordChoice [0] == 6:
        thisWord = word6
        thisWord_color = 'Blue'

What I tried is:

if wordmousep.isPressedIn(mywordlist1p): #mywordlist1p is the name of the component calling $mywordlist1x
    word_accuracy = 1
    thisExp.addData('word_accuracy', word_accuracy)
else:
    word_accuracy = 0
    thisExp.addData('word_accuracy', word_accuracy)

However, I do not know where to locate this code within the randomization or if it is the correct way to do. Your help is much appreciated.

Hi There,

Hi There!

Have a column in your file that indicates the component name that should be clicked. Then in your code component try this in the end routine tab:

if mouse.clicked_name[-1] == correctAns:
    corr = 1 
else:
    corr = 0

Sorry, I am not sure if I understand you correctly.

Where should I define “correctAns” variable? What is [-1] item in the mouse.clicked_name? In the data, mouse.clicked_name is the component that was clicked, e.g. mywordlist3p. S

I do not know which component to be clicked because encoded items will be randomly determined by the code.

UPDATE:

    elif wordChoice [0] == 6:
        thisWord = word6
        thisWord_color = 'Blue'
        corr_AnsW = 'mywordlist6p'
        thisExp.addData('corr_AnsW',corr_AnsW) #thisExp.addData('corr_AnsW','mywordlist6p') is tried as well

[/quote]
Now I can see the correct answer in the .csv file. But the thing is I want it to be automatically give accuracy score

I tried this in both Begin and End Routine and even in End Experiment but it always gives 0 to each column in the .csv file.

if wordmousep.isPressedIn (corr_AnsW):
    word_accuracy = 1
    thisExp.addData ('word_accuracy', 1)
else:
    word_accuracy = 0
    thisExp.addData ('word_accuracy', 0)