OS (e.g. Win10): MacOS version 12.0.1 PsychoPy version (e.g. 1.84.x): v2022.2.5 Standard Standalone? (y/n) If not then what?: y What are you trying to achieve?:
Hi I am working with Code component in Builder to record multiple responses. Specifically, I have 5 possible responses by pressing “q”, “w”, “s”, “a” and “x” in keyboard. At the same time, I also record another variable (position_XY) for each response. The codes are as follows:
Now my problem is that sometimes the experiment could run successfully. But sometimes it reported an error about the response and exited. And it seems that the error was more likely to appear when response was made very quickly. The error is:
Assuming keys or keys_exp (as in your error message) contains a list of Keypress objects (from getKeys() method), I’d say that the keyboard component you created did not register any keypresses or got cleared before you check for the actual keys.
Can you provide some more context (eg. where is this code placed, when do you check for keys, how is keys initialised, etc)?
It seems that sometimes the response was not recorded so the “keys” is “”, and consequetly the index error was reported when running the if loop mentioned above.
I have modified the code as follows and now there is no such error reported.