psychopy.org | Reference | Downloads | Github

Problem with specifying allowed keys via script (or variable in xlsx file)

If this template helps then use it. If not then just delete and start from scratch.

OS Win10
PsychoPy version: v2020 1.3
Standard Standalone? (y/n) y
What are you trying to achieve?: Specifying a variable list of allowed keys

I am specifying the allowed keys based on a paremeter in the excel input file that describes the type of the trial, as follows:

if (type == "vignette"):
    possibleKeys = ['space']
elif (type == "question"):
    possibleKeys = ['1','2','3','4','5']
else:
    possibleKeys = ['f']

(sorry, the necessary whitespaces are there in the script, but get taken out when posting)

The allowed keys are set to possibleKeys WITHOUT the $ that is otherwise use to set object properties,
as indicated in an earlier post on the topic.

The experiments starts running but stops when the key response is first activated, with this error,
called from the…last_run.py script

error in script at line 293:
if not type(possibleKeys) in [list, tuple, np.ndarray]:
    if not isinstance(possibleKeys, str):

with the message:

TypeError: strObject not callable

(Btw, the same happens if I specify the list of possible keys as a variable in the input file)

The astonishing thing is, if I comment out the whole “if” statement that checks whether the list
of allowed keys is properly specifiied, the program works exactly as intended.
This, however, means that I have to do that every time I change something in the builder version.

Kind regards,
Holger

PS: I checked for the error message online, and most forums say it has to do with “str” being used as a variable. However, I have not declared a variable with that name.

As edited above:

Can you show the post that says that? This is the opposite of what I’d suggest: that you should use the prefix like $possibleKeys to indicate to Builder that you have provided a variable name rather than a literal list of keys.

re:

In the below topic, the pen-ultimate message says that the dollar sign ($) should not be used.

It also makes sense, as in the builder view, the $ is already there in front of the allowed keys box

I just managed to resolve it myself, I was blinded by the “str” in the error message.
It had to do with the use of reserved variable names. I have three different type of trials,
and called that variable “type”. This then obvsiouly leads to problems if the “type” function is used.

Renaming the variable in the input file to “trialType” resolved the issue.