TypeError: Cannot use 'in' operator to search for 'backspace' in undefined

URL of experiment: Noah Hager / javatranslatetest · GitLab

Description of the problem:

Hey guys, i’ve been trying to get a PsychoPy experiment that i mostly programmed in Python (PsychopyBuilder) to get to work on Pavlovia, so i’ve been trying to translate it to JS (which isn’t my forte at all) but i need to make it work beacuse its for my bachelors thesis hahaha… i’ve been getting stuck on this one error message recently that pops up right at the beginning when trying to run it online, the error message says “TypeError: Cannot use ‘in’ operator to search for ‘backspace’ in undefined”.

Here’s a screenshot of where the error appears, and i copied out the piece of code:

// Run ‘Each Frame’ code from code_4
var _pj;
function _pj_snippets(container) {
function in_es6(left, right) {
if (((right instanceof Array) || ((typeof right) === “string”))) {
return (right.indexOf(left) > (- 1));
} else {
if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
return right.has(left);
} else {
return (left in right);
container[“in_es6”] = in_es6;
return container;

It seems to be a problem where “right” isn’t defined previous to this code snippet, but i can’t for the life of me figure out where this should have happened…

any help or info on this would be greatly appreciated because i’ve been stuck on this for a while now…

I linked my GitLab at the top where all the resources and code are uploaded if people want to look at it!

Thanks for any help!
CHeers, Noah

Please show line 706 so we can see what “right” is supposed to be. It may be that you are trying to search for backspace in an array of keys which hasn’t been created because no key has been pressed. In this case I use the following:

if key_resp.keys:
     if 'backspace' in key_resp.keys:
          do stuff

thanks for your reply man!

Heres line 706 and following:

Idk if this makes the problem more apparent but im greatful for any help i can get hahaha!!!

The issue is the key_return_ID.keys is undefined at the point of the error. If that code is in Each Frame, then you can solve the issue by adding if key_return_ID.keys: as per my last post.

thank you so much!! that fixed it!!