Key press to skip routine works in PsychoPy but not Pavlovia

URL of experiment: worry [PsychoPy]
OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): 2021.1.3
Standard Standalone? (y/n) If not then what?: Y
What are you trying to achieve?: Force end of routine if ‘enter’ is pressed

What did you try to make it work?:

So this is what my builder looks like, for reference. I don’t know JS, so don’t understand why this code doesn’t work (was automatically ‘translated’ from Python).


What specifically went wrong when you tried that?:
Error message: Cannot use ‘in’ operator to search for ‘return’ in undefined

Screen was then stuck on that frame and nothing I pressed could change it.

Thank you, much appreciated!

The issue is that your keyboard components appear as undefined on Pavlovia until a key is pressed.

There are three different solutions to this.

  1. If you are ending the routine on a key press then you could put the code in End Routine. Why do you have two keyboard components (key_resp and cardOpeningStartsHereKeys) monitoring for the same key press?

  2. You could start with if key_resp != undefined: so that you only check for the keys if a key has been pressed. The problem with this method is that it doesn’t work offline.

  3. You could ditch your keyboard components in favour of keys = event.getKeys() which will then be defined even when empty. (if 'return' in keys:). You’d need to also define event as per my crib sheet.

1 Like