Experiment works locally, but pops type errors in pavlovia

URL of experiment: Phase1Procedure [PsychoPy]

Description of the problem: I have a series of loops so participants can listen to practice examples as many times as they like before moving to the next one. (Attached image of my flow, with one the loop routines pulled up in builder).

The experiment works OK locally, although hitting spacebar to end the loop results in one more repetition of the loop before it truly ends.

Online, however, it crashed when I try to initiate the first loop routine. Every browser throws an error with slightly different wording but similar to:

Unfortunately we encountered the following error:

  • TypeError: right is not an Object. (evaluating ‘left in right’)

Try to run the experiment again. If the error persists, contact the experiment designer.

There are other loops in my experiment that I tested on pavlovia previously and they work just fine. It’s these practice loops that have an issue. I see a lot on here about it being a JS issue, but I am not a coder, and don’t know where to begin to solve it.

The JS translation of the code component is below. I am guessing “right” is not the wording it wants to use online, but I don’t know what to change it to.

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;
}
_pj = {};
_pj_snippets(_pj);
if (_pj.in_es6(“space”, slide2Keys.keys)) {
slide2Loop.finished = true;
}

Thanks so much.

I think you probably have some code like

if 'space' in slide2Keys.keys:

However, this will give an error if you run it before slide2keys starts (at 1 second).

You need to first check slide2Keys.keys…

if slide2Keys.keys:
    if 'space' in slide2Keys.keys:

This makes sense! I made the changes, I tried both what you suggested initially and then also putting my original code in the end routine section. Both times resulted in the same thing: when I go to my procedure, it stays stuck on “initializing experiment” and won’t load at all.

I fixed your indents (preformatted text) but you need to make sure your final line is indented twice.

if slide2Keys.keys:
    if 'space' in slide2Keys.keys:
         slide2Loop.finished = True

However, how is the routine ending? If the routine only ends on a key press then your original code should work in End Routine.

I looked through some old posts and found others who had this same issue, and it seems like there must still be an error with pavlovia reading the JS for this bit of code? It’s stuck on “initializing experiment.”

What error can you see in the Browser console?

You mean just in chrome/safari etc? No error. It simply says initializing experiment on a white screen and never changes.

Developer Tools

Use Developer Tools (Ctl-Shift-I in Windows/Chrome, Cmd-Opt-J or Cmd-Opt-I in Mac/Chrome, F12 in IE/Edge, Ctrl-Shift-J in Windows/Safari, Ctrl-Opt-J in Mac/Safari) to view errors via the browser console if you aren’t getting sufficient information from PsychoPy. You can also add print(X) (which translates to console.log(X) ; where X refers to the name of your variable) to check the value of a variable X at a particular point.

Tutorial tutorial_js_console_log

Thanks!

I tried chrome and it threw two errors

Uncaught syntaxerror: octal
Literals are not allowed in strict mode

Failed to load resource: the server responded with a status of 404 ()

In safari:
Syntaxerror: decimal integer literals with a leading zero are forbidden in strict mode

Do you have any numbers written as e.g. 03 instead of.03 ?

Is there a quicker way to check than going through everything I have in builder? It does seem to be related to this same piece of code, but I don’t have numbers beginning any lines there.

The Browser console should give you a line number with a link to the offending line of JS code.

Thanks! For some reason in Chrome the links didn’t open anything, but on Firefox they did - I had one of my loops set to 00 by accident. That was the issue. Thank you so much!

1 Like