Mapping different number keys as allowable within loop

Hi, I’m very new to PsychoPy and am struggling to make a loop where trial 1-4 appear in each corner of the screen and have their respective number as the only allowable key.

My conditions are in a trial definition file, and I have the Keyboard Component changed to set every repeat, looking at the variable BoxTestCresp. The cells in this variable are 1,2,3,4. Given that you don’t need to put the letter keys in quote marks when using a condition file I would’ve thought that it’d be okay to do the same for the number keys.

When I run the experiment, it crashes out with this error:

```AllowedKeys variable `BoxTestCresp` is not string- or list-like.

I vaguely understand what this means, but it still crashes out if:

  • I type ‘1’,‘2’,‘3’,‘4,’ in each cell, like how I would if I wanted all buttons mappable at all times and am just typing out the string
  • I type '1,'2,'3,'4. I know Excel learns to map cells as a string with just the 1 quote mark so thought this would be a fix.
  • I use the Format Cells function in Excel to declare BoxTestCresp as text not number.
  • I call them num_1 num_2 num_3 num_4. I saw someone in another forum suggest this as an answer.

It doesn’t crash out if I use ‘‘1’,’‘2’,‘‘3’,’‘4’ (two single quotes, one single quote) instead, but even then it doesn’t accept the number key as input.

It does work if I remapped to a,b,c,d, but the response box only takes 1234 so it needs to be these keys.

What am I missing in order to call the specific number key through this loop successfully?

Hi @ram.soberts,

Formatting trial information is certainly difficult, especially when Excel tries to secretly change formats on you. Try formatting your BoxTestCresp column as a “list of strings”. A list is indicated by using square brackets [ ], items in a list are separated with a comma , and string-items are indicated with single-quotes ' ' or double-quotes " ".

  • e.g. for the single allowed key 1, the format should be ['1']
  • e.g. for multiple allowed keys 1 2 3 4, the format should be ['1','2','3','4']
    Using this style of “list of strings” seems to work around Excel’s tendency to secretly change formats.

Hope that helps,
-shabkr

Notes for .csv:
If you use .csv files for handling your trials, you may run into similar issues because of syntax sensitivities.

  • for a single allowed key 1, the format can be ['1'] or ["1"] or even "['1']" but not "1"or '1' or '["1"]'
  • for multiple allowed keys 1 2 3 4, you must use the following format "['1','2','3','4']" (the double-quotes are important!). Surrounding the whole list in double quotes allows commas to be used in the .csv (see Stackoverflow’s discussion on comma’s in csv or Wikipedia’s page on csv syntax

I should mention, these solutions were tested in PsychoPy 2022.2.4.

This worked thank you so much!