Key response right and wrong answer

Hi! I want to know how can I put a response “right answer”, “wrong answer” type. The answer will be always wrong if the participant press the same key more than once. They would be right if they press any key but the last one.
Do I need code?

You would need code if there are multiple correct answers.

For example.

Begin Experiment

oldKey = ''

End Routine

score = 0
if oldKey != key_resp.keys:
     score = 1
     oldKey = key_resp.keys
thisExp.addData('Score',score)
1 Like

Hi! Sorry for answering until now. I did it and I have something like this (it works, thanks):

Begin experiment

oldKey = ''  
score = 0   

Each frame

if key_resp_3.keys:
    currentKey = key_resp_3.keys[-1]  # Get the last key pressed

    # Compare with the previous key
    if currentKey != oldKey:
        feedback_text.text = "Correcto"  
        oldKey = currentKey  # Update the previous key
    else:
        feedback_text.text = "Incorrecto"  

End routine

# If the key was different from the previous one, save a value of 1 (correct), otherwise 0 (incorrect)
score = 0
if oldKey != key_resp_3.keys[-1]:
    score = 1

thisExp.addData('Score', score)  # Save the score in the data

Now, I replicated the same code for the following routines. However, when starting each routine any key between ‘1’, ‘2’ and ‘3’ should be correct, but this does not happen. If the last key pressed in the previous routine was ‘2’, the next routine will mark it as incorrect if it started there. Do you know how I can solve it?

Hello

I think that you need to “reset” oldkey to " " for the first trial in routines following your first routine. Something along the following lines
Begin Routine

if trials.thisTrialN == 0:
    oldKey = " "

Best wishes Jens

2 Likes

Hi! I try it but it is still not working, it seems like nothing changed. But thanks, I will try to find more info.

If nothing appears to change, try Ctrl-Shift-R or an incognito tab to ensure you are seeing the latest version.

1 Like