The issue is that your keyboard components appear as undefined on Pavlovia until a key is pressed.
There are three different solutions to this.
-
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?
-
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. -
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.