# Specify allowed key responses in loop through conditions file

**URL:** <https://discourse.psychopy.org/t/specify-allowed-key-responses-in-loop-through-conditions-file/8322>\
**Category:** Builder\
**Created:** [July 2, 2019, 1:43pm UTC](https://discourse.psychopy.org/t/specify-allowed-key-responses-in-loop-through-conditions-file/8322 "2019-07-02T13:43:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![visual.narrative](https://avatars.discourse-cdn.com/v4/letter/v/ed8c4c/32.png) [@visual.narrative](https://discourse.psychopy.org/u/visual.narrative)\
**Post date:** [July 2, 2019, 1:43pm UTC](https://discourse.psychopy.org/t/specify-allowed-key-responses-in-loop-through-conditions-file/8322/1 "2019-07-02T13:43:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [July 2, 2019, 2:26pm UTC](https://discourse.psychopy.org/t/specify-allowed-key-responses-in-loop-through-conditions-file/8322/2 "2019-07-02T14:26:43Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![visual.narrative](https://avatars.discourse-cdn.com/v4/letter/v/ed8c4c/32.png) [@visual.narrative](https://discourse.psychopy.org/u/visual.narrative)\
**Post date:** [July 9, 2019, 12:27pm UTC](https://discourse.psychopy.org/t/specify-allowed-key-responses-in-loop-through-conditions-file/8322/3 "2019-07-09T12:27:56Z")

</div>

Thanks a lot!
