Error in giving feedback after a trial

@m-macaskill But the ones with quotes were the keys, not the corrAns. So, I thought the quotes in the keys were automatically added and doesn’t have anything to do with the missing quotes in corrAns. Should I just add quotes in the corrAns?
keys: '8’
corrAns: 8L
False

I’ve also tried switching to .csv file, still it didn’t change anything, the problem still exists.

The quotes are fine. They aren’t part of the string, they just indicate that it is a string rather than a number (i.e. that the person has entered the ‘letter’ 8). It’s the fact that corrAns isn’t a string may be the problem here. The keyboard component knows about this issue and forces numbers into strings if needed (taken from your Builder code above):

if (key_resp_2.keys == str(corrAns)) or (key_resp_2.keys == corrAns):
    key_resp_2.corr = 1
else:
    key_resp_2.corr = 0

However, @jon 's suggested testing code doesn’t do this coercion, so it is telling you the two values aren’t equal. i.e. I think his code should read like this to match what the keyboard component does (forcing corrAns to be a string rather than a long integer):

print(str(corrAns) == key_resp_2.keys)

But this thread has gone on so long, I think I’ve lost track of the original error. It’s the keyboard component itself that is getting things wrong by not making the correct comparison right? That is still mystifying then, as it should be forcing the two values to be equivalent.

Thanks Michael!
It did solve the problem!
There’s a small problem though, the output in csv file still detected that my responses were all wrong. But it’s okay, at least right now the feedback can correctly tell me whether my responses were correct or not.

Once again, thank you guys, you helped me a lot!!

Yes, the code checking the Keyboard Component checks both the actual value (which in this case gives False) and the string equivalent (which in this case gives True). I can’t replicate the issue so I’m giving up on this thread.

Hi Jon…
I also have this issue on my mac. With the code you posted above to print the output, I get the folllowing output:

keys: ['2']
corrResp: 2
False
keys: ['3']
corrResp: 3
False
keys: ['1']
corrResp: 1
False
keys: ['4']
corrResp: 4
False

Any ideas? I tried changing my stimuli file to have the corrResp as ‘1’ ‘2’ ‘3’ ‘4’ rather than just 1 2 3 4 but still didn’t work.

Thanks
Matt

Update: This is also the same outcome if I change the code to:

print("keys: %r" %(response.keys))
print("corrResp: %r" %(corrResp))
print(str(corrResp) == response.keys)

It’s baffling me!

Yours is slightly different but the technique to try and understand it is the same. In your case notice that the keys: show [‘4’] rather than ‘4’ indicating a list of keys rather than a single key.

I think this is because you’ve told PsychoPy to record “all keys” rather than just the first or last key. If you allow multiple keypresses to be recorded in a trial then provide a single answer as “correct” it isn’t clear how to handle it. “Correct” if the key was in the list? “Correct” if only that key was in the set? etc.

This topic was automatically closed after 3 days. New replies are no longer allowed.