| Reference | Downloads | Github

Correct response variable not recognised for new experiment with new version: 'key_resp.corr' always FALSE

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2021.1.0
Standard Standalone? (y/n) y
What are you trying to achieve?: Assign correct keyboard response to variable in code component, have it recognised as “Correct answer” by subsequent keyboard component

What did you try to make it work?: Tried a simple new "experiment’’ with just 5 loops of trial, a code assigning one key as answer, and keyboard component after it, in order, with default allowable keyboard responses, one of which assigned as correct. Tried using ‘dollar sign’ and not using it ahead of variable name in “Correct answer” textbox of keyboard component dialog (apparently not needed anymore but tried it anyway). Tried “y” and “space” as correct assigned answer. But no response is recognised as correct. Data file shows “trial_resp.corr” = 0 all the time. Tried opening an old experiment opened in this version of PsychoPy; it still works, with same correct answer logic (but the dialog box opens up differently, it doesn’t show the “$” sign ahead of the Correct answer box, but same version of PsychoPy). So just creating a new experiment seems to fail in this basic way.

No error message throughout any of this.

Please could you show a screenshots of your keyboard component and code component?

just from dummy simple effort to check error in experiment being re-written in new version (because of old one no longer updating last-run file):
same line above given redundantly into “Begin Routine”. Various keys tried as answer other than space …
also tried with ‘dollar sign’ ahead of ANSWER, and ‘last key’ not just first key.
after pressing space all the time:
This is from actual experiment where correct answer from code “RESPONSE_EXP” is being added to data:

I’m not sure. I definitely have managed to use the correct answer field online.

just in case it wants a list instead of a string.

No, this doesn’t solve it. Haven’t tried online, using Psychopy. And yes, always used to work. Just doesn’t work for new experiment in this new version anymore

I’ve just noticed you’re using 2021

@TParsons might this be a new bug?

Could you upload the psyexp file? It could be a bug - possibly because Correct Answer for Keyboard is now validated as a list - but I’d need to have a look at the Python code from your experiment to make sure

1 Like

ok, can’t load my whole experiment but here is the dummy bit just to check that the usual, simple assignment of correct response value to a variable for keyboard component to check if response correct works; it wouldn’t using this new version of PsychoPy, although it can handle it in the same way from old experiment. it seems to recognise the difference, even throws up a slightly different dialog for keyboard component if experiment written in older version. So this is just stripped back focus on the issue; you get a feedback bit too. You can see I’ve tried your list representation of the value, or you can go back to the single scalar value as before, which, again, still works from old experiment in this new version. it’s writing in new version that this doesn’t work anymore, one way or the other. maybe i’m doing something differently but just with these few settings … as always before …
dummy_2.psyexp (11.1 KB)

tried also using [ANSWER] rather than just ANSWER or $ANSWER in the keyboard component’s “Correct answer” box, paired with the same or alternative form in the prior code giving a value to answer. Also tried running this new script, written and run within 2021.1.0 Builder, but switching version in settings to 2020.2.3, and it still doesn’t recognise the value; key_resp.corr still always returns as 0.

I doubt it’s the issue, but do try using corrAns instead of ANSWER just in case ANSWER’s a protected variable name.

nice try. No. Same thing. Always .corr = 0, always given 0 as its value whether key matches the key given to correct response variable or not. I was originally using “RESPONSE_EXP” as name of variable in experiment when problem arose in rewriting the experiment from scratch, in this new version. Had worked in old version, written/saved in 2020.2.3, but that has stopped accepting any edits, updating “”, as raised in association with others elsewhere. That’s only reason why rewriting from scratch, otherwise worked before, Just this not working in new version now

Another user seems to have found the same problem lately, more recently:

Have tried uninstalling new version (2021), in which this was written, and reverting to 2020.3.10, but the psyexp file won’t run in that, nor will another experiment written in the new version; error is “opacity cannot = NoneType”; changed opacity to 1 in the text components, same error. Also the .py file isn’t generated from “Compile” in the new version; dialog pops up “… .py file not found”; and trying to do this in earlier version encounters multiple issues via “” or similar. Won’t raise as separate issues as can’t investigate exhaustively at this stage. Just noting that here in case you want to run the .psyexp file attached above and check it out.

What did you find by running the psyexp you asked me to upload for you? Did you confirm the issue or found an error on my part? Or could you not run the file? Or what else? Please advise…

Ah I’ve found the problem - it’s the new param types in 2021.1. Essentially, it sees whatever you give a Keyboard for it’s correct answer as a list, not a string. This is only a problem for experiments made in 2021.1.0 - experiments made earlier will have the old param types and so will be interpreted fine. I’ll fix this in 2021.1.1, but for your specific experiment I’m afraid you’ll have to do a bit of manual substitution - you could either remake the Keyboard components again in the next version, or open the .psyexp in notepad (or equivalent program) and replace anything like this:

<Param name="correctAns" val="space" valType="list" updates="constant"/>

with this:

<Param name="correctAns" val="space" valType="str" updates="constant"/>

(val might differ between components, but the rest should stay the same, so you can use CTRL to find them all quickly)

Sorry for the inconvenience! It’s something I missed when refactoring.