I have a full working experiment in pschoPy, but I am getting an error when I try to generate any javascript. I have tracked the problem down to using a variable name in the “allowed keys” field of a keyboard component. I can successfully generate the javascript if I replace the variables with manually specified keys, but lose important functionality for my experiment.
The problem and error message (repasted below) seem to be the same as in this post from 2021, however that thread says it should have been patched in a much earlier release. I am running v.2024.2.2 on Mac OS 13.2.1.
Error message:
Traceback (most recent call last):
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/experiment/components/keyboard/init.py”, line 409, in writeFrameCodeJS
File “”, line 1, in
NameError: name ‘key1’ is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/app/builder/builder.py”, line 894, in fileExport
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/scripts/psyexpCompile.py”, line 83, in generateScript
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/scripts/psyexpCompile.py”, line 221, in compileScript
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/scripts/psyexpCompile.py”, line 194, in _makeTarget
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/experiment/_experiment.py”, line 422, in writeScript
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/experiment/routines/_base.py”, line 903, in writeEachFrameCodeJS
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/experiment/components/keyboard/init.py”, line 411, in writeFrameCodeJS
psychopy.experiment.utils.CodeGenerationException: choice_2:
key1 is the name of one of the variables in the “allowed keys” field (specified as key1, key2) and choice_2 is the name of the keyboard component in question.
Thanks in advance for any help!