psychopy.org | Reference | Downloads | Github

Check if typed response in textbox is correct

Hello all,

I am working on a section in my experiment that includes an editable textBox component for participants to use when they respond to the task. Participants see a string and mark it as grammatical (G) or nongrammatical(N). Currently, the data file shows the participant response as this:

image

I would like to be able to check for accuracy - I have a list with the correct answers, but I was wondering if/how I might be able to place this in the data file, and have Psychopy check if the values that the participant inputs match the values on the list. I was also wondering if there is a way to only record what the participants type, without the “Response:” there, as I think that might interfere with checking for accuracy.

Thank you!

Hi There,

This youtube video might help! ’ How to check if a typed response is ‘correct’ in PsychoPy’

Becca

PS. I have adjusted the title of this question to be a bit more informative for future users :slight_smile:

Hi Becca,

Thank you for the video! However, I was wondering if this would work with the way my experiment is set up. The trial I am trying to check accuracy already has a loop, with strings that the participant responds to (trial _2 in the image below). If I nest the loops like this, will it be able to check the accuracy after the first loop has gone and the participants have typed their responses? I also don’t want the feedback to show up on the screen, just to be included in the data file.

Sure it will work a similar way.

  1. Add a code component to your C_Strings routine.
  2. Assuming key_resp_2 is how they submit their answer, in the ‘eachframe’ tab of your code component type:
if key_resp_2.rt:
    if textbox.text ==corrAns:
        corr = 1
    else:
        corr = 0
    trials_2.addData('correct', corr)

where ‘corrAns’ is a column in your conditions file with the desired response.

Becca

Hi Becca,

I used this code component, and while it worked, I think that having two loops caused the experiment conditions to run repeatedly, instead of just once. I removed the second loop and just put the file with the strings and the correct answers into one loop. However, now my experiment cuts out once it reaches that portion of the experiment, with no indications as to why.

Hi There,

Yes, you should only need one loop (I assumed the second loop was part of your design (i.e. that you wanted to repeat a loop several times) rather than associated with checking accuracy!).

Try adding some print statements to see where your experiment is ‘working’ until

e.g.

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

From this you should be able to see in your stdout window which parts of the code were successfully executed before the crash. If you do not get any information in your stdout window, this could be a bug. Try closing psychopy, reopening it and then opening your .psyexp file through the open file icon in psychopy, rather than clicking on the .psyexp file directly

All the best,
Becca

Hello Becca,

I tried both methods, but the stdout window still is not showing me any information.

Actually, I just updated to 2020.2.8 and now it’s giving me the information. Thank you for all your help!