TypeError: Cannot read property 'length' of undefined

Trying to get psychopy to only move on after correct answer. However, have now hit this issue:


I’m assuming it has something to do with this code but not sure how to debug or check…

NB. There is an issue already solved with a similar title here but it doesn’t seem relevant to this specific issue Cannot read property 'length' of undefined

@TheSav, this is because online tasks leave the keyboard.keys variable undefined until a keypress is made. You could instead try changing the Python code to the following, so that length is not specifically checked, but will still evaluate as true or false depending on the existence of a key press:

if key_resp.keys:

which should translate to

if (key_resp.keys) {
  // etc
1 Like

Superb, that fixed the issue!

Worked for me too! Thanks!