Allowed Keys Set Per Repeat Error

OS: Win11
PsychoPy version: v2023.2.2
What are you trying to achieve?:
The allowed keyboard responses are related to the condition shown. Thus, I want the allowed keys to set per repeat and call the allowed responses from my conditions file.

Here is the experiment and conditions file referenced:
LetterSeries.psyexp (46.9 KB)
pracConditions.csv (688 Bytes)

What did you try to make it work?:
I have ensured (to the best of my ability) the spreadsheet is in the right format and the column names are correctly labeled. I’ve read a lot of the previous forum posts on this same error, but none of the solutions (e.g., formatting the allotted keys correctly, fixing column names, using .xlsx instead of .csv) have worked.

What specifically went wrong when you tried that?:
When I try to run the experiment, it gives me the following error after loading the instruction routine: “if not type(posKeys) in [list, tuple, np.ndarray]:
UnboundLocalError: local variable ‘posKeys’ referenced before assignment”

Any advice is greatly appreciated! I’ve been troubleshooting for a week, but decided it was finally time to ask for help.

Hi @amycosta,

I hope I’m not too late to help here! I think I’ve solved the problem in the attached files. The issue was to do with the way that the list of allowed keys was being read from your conditions file. PsychoPy is expecting a list of strings, defining which keys are allowed, but the contents of posKeys was being read as a string, rather than a list.

To solve this I’ve done two things:

  1. Added a code component to the start of your practice trial routine which converts the contents of the current value of posKeys into a list of strings
  2. So that this works properly, I’ve changed the contents of posKeys to be just, for example, abcde rather than [‘a’,‘b’,‘c’,‘d’,‘e’].

I hope this helps!

Kim
LetterSeries.psyexp (48.8 KB)
pracConditions.csv (478 Bytes)