Accuracy Not Appearing in Data File

Hello all,

I am working on an experiment where the participant sees a string, and then must type whether it is grammatical (G) or nongrammatical (N). Right now, the participant responses are being recorded using the Textbox component. I have an excel file with the strings and correct answers on it, and I was trying to have the experiment check for the accuracy of the participant response. This is the code I am trying to use:

print('checking accuracy')
if key_resp_2.rt:
    if textbox.text == corrAns:
        corr = 1
        print('Answer was correct!')
    else:
        corr = 0
        print('Answer was incorrect!')
    trials_2.addData('correct', corr)
    print('data saved')

However, none of the information that is supposed to be printed is appearing in the data file, so I am not sure that this is working as it should. Any help would be appreciated, thank you!

PsychoPy version: 2020.2.8

Why are you recording the response with a textbox component? If you use instead a keyboard component it should be very easy to add a correct column in the data file without any extra code.

tandy

I think you mean thisExp.addData('correct',corr)

I had tried to use a keyboard component earlier on in the experiment, but the problem was that I also had one that I was using for the participant to use to continue on to the next string by pressing space. If I remember correctly, when I tried to use another keyboard component, the ‘space’ keyboard component interfered with that, so the solution was to use a Textbox component.

When I put this in, I could see that it checked for accuracy in the stdout window, and it said ‘data saved’, but it didn’t actually appear in the data file.

Why not then simply use just one keyboard component for the response and a code component for ending the routine?

# e.g. in the each frame tab
routine_end = event.getKeys('space')

if 'space' in routine_end: 
   continueRoutine = False

Sorry, I remembered what the actual issue was - I couldn’t use the keyboard component because for this trial, the string that the participant looks at and the response needed to go on the same screen. So with the textbox, the string can be up on the screen and the participant can see their response on that same screen. My first trial is set up the way you suggested, but it doesn’t work for this second trial.