| Reference | Downloads | Github

Specify allowed key responses in loop through conditions file

**PsychoPy version 3.07

I am looping over a keyboard response component and want to specify the allowed keys for each loop iteration in a conditions file.

To do so, I set the value for “Allowed keys” to “$key” and created a conditions file with a column which looks like this:


However, when I tried running the experiment, I got an error (see below). Any ideas how to solve this?

Here the error message:

Traceback (most recent call last): File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\”, line 352, in writeFrameCodeJS keyList = eval(allowedKeys) File “”, line 1 $key ^ SyntaxError: invalid syntax During handling of the above exception, another exception occurred: Traceback (most recent call last): File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\”, line 2281, in onPavloviaRun self.fileExport(htmlPath=self._getHtmlPath(self.filename)) File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\”, line 1682, in fileExport target=“PsychoJS”) File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\”, line 2242, in generateScript psyexpCompile.compileScript(infile=self.exp, version=None, outfile=experimentPath) File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\scripts\”, line 51, in compileScript script = thisExp.writeScript(outfile, target=targetOutput, modular=True) File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\”, line 238, in writeScript self.currentRoutine.writeEachFrameCodeJS(script) File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\”, line 279, in writeEachFrameCodeJS comp.writeFrameCodeJS(buff) File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\", line 355, in writeFrameCodeJS self.params[“name”], “Allowed keys list is invalid.”) psychopy.experiment.utils.CodeGenerationException: key_resp_5:

Hi @visual.narrative, you should remove the dollar sign from the variable name (it is already recognised as a potential variable). Then, in your conditions file, set your key lists like the following for each trial/row.


Thanks a lot!