psychopy.org | Reference | Downloads | Github

Specify allowed key responses in loop through conditions file

**Win10
**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:

**key
‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’
‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’
‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’
‘1’,‘2’,‘3’,‘4’,‘5’,‘6’,‘7’
‘y’,‘n’
**

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\keyboard_init_.py”, 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\builder.py”, line 2281, in onPavloviaRun self.fileExport(htmlPath=self._getHtmlPath(self.filename)) File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 1682, in fileExport target=“PsychoJS”) File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py”, line 2242, in generateScript psyexpCompile.compileScript(infile=self.exp, version=None, outfile=experimentPath) File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 51, in compileScript script = thisExp.writeScript(outfile, target=targetOutput, modular=True) File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment_experiment.py”, line 238, in writeScript self.currentRoutine.writeEachFrameCodeJS(script) File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\routine.py”, line 279, in writeEachFrameCodeJS comp.writeFrameCodeJS(buff) File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\keyboard_init.py", 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.

['1','2','3']
['a','b','c']

Thanks a lot!