Data file does not indicate whether a response is correct or incorrect

I am using version 3.0.5, and on my conditions file I have a “corrAns” column, but when I tell the program to “store correct” and put $corrAns for what the correct answer should be, it doesn’t display whether the participant’s answer is correct on the data sheet or not. Furthermore, it returns this code:

-------Ending Routine “test”-------

for thisComponent in testComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
# check responses
if testresponse.keys in ['', [], None]:  # No response was made
    testresponse.keys=None
    # was no response the correct answer?!
    if str(corrAns).lower() == 'none':
       testresponse.corr = 1;  # correct non-response
    else:
       testresponse.corr = 0;  # failed to respond (incorrectly)
# store data for tests (TrialHandler)
tests.addData('testresponse.keys',testresponse.keys)
tests.addData('testresponse.corr', testresponse.corr)
if testresponse.keys != None:  # we had a response
    tests.addData('testresponse.rt', testresponse.rt)

Even when no response is given, a 0 is still displayed in the “testresponse.corr” column. Any suggestions?

You should probably show us a screenshot of your keyboard component’s settings, and some example content from your conditions file corrAns column.

Sure thing,


Screen Shot 2020-01-07 at 8.47.43 PM

Is this what you mean?

Yes.

There is zero correspondence between the 6 allowed keys and the multi-character words in the corrAns column, so the answer can never be correct.

Also, you have it set to collect multiple keypresses by “Store: all keys”. This generally doesn’t make it possible to compare responses to a stored answer, which both need to be single characters.

Oh, wait a moment, you’re intending for people to type out a whole word (and presumably allow for all of the letters in the alphabet)?

The keyboard component doesn’t work like that. It stores a list of keypresses rather than concatenating them into a single string, so you’d need to use some code to process the list. You’d probably also need to give onscreen real-time feedback of typing, as a lot of responses will be contaminated by typos.

There are a few examples of that if you search this forum, e.g.

and I think you could even download a working example from here, to modify as needed:

Are you referring to a code that displays the text as it is being typed so the subject can see what he is typing? If so, I already have that.

Are you saying that for an answer to be listed as correct, it has to be only one character?

Where can I find a code like this?

You can’t be using that sort of custom code and use the keyboard component to do things as well: the two will conflict. i.e. either the keyboard component or your custom code will detect the keypresses. Whichever one gets there first, wins. So you should probably just delete the keyboard component and have everything done via code.

You already have it, as your custom typing code should be doing that already (i.e. collating all the keypresses together into a single string variable).

You would just need to make the comparison explicitly yourself. e.g. at the end of the routine, code like this:

if your_response_variable_name == corrAns:
    # store in the data file manually:
    thisExp.addData('answer_correct', 1) # or True or 'Yes', or whatever
else:
    thisExp.addData('answer_correct', 0)

So I should get rid of the keyboard component but retain all the code that goes along with it?

When I added this in, I used “recallresp” as the variable name, as that is the column in the data sheet where all the letters in the subject’s response were joined to make a word, but when I try to run the experiment now it says that recallresp is undefined. Should I use something like .join(testresponse.keys)? Also, if I put this in a code component, which heading (like the “begin experiment”, “begin routine” etc.) should it go under?