# Experiment works locally, but pops type errors in pavlovia

**URL:** <https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466>\
**Category:** Online experiments\
**Created:** [April 6, 2022, 5:55pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466 "2022-04-06T17:55:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![erober69](https://avatars.discourse-cdn.com/v4/letter/e/76d3ee/32.png) [@erober69](https://discourse.psychopy.org/u/erober69)\
**Post date:** [April 6, 2022, 5:55pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/1 "2022-04-06T17:55:03Z")

</div>

URL of experiment: [Phase1Procedure [PsychoPy]](https://run.pavlovia.org/ecr75r/contour-phase-1/)

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.

 ![Screen Shot 2022-04-06 at 1.47.07 PM 1](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/4/0465e19bd9c95df4713ee92e3991e3b5f8aff583.jpeg)

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.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [April 6, 2022, 6:02pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/2 "2022-04-06T18:02:34Z")

</div>

I think you probably have some code like

```auto
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…

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

```

---

<div class="post-metadata">

**Author:** ![erober69](https://avatars.discourse-cdn.com/v4/letter/e/76d3ee/32.png) [@erober69](https://discourse.psychopy.org/u/erober69)\
**Post date:** [April 6, 2022, 6:06pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/3 "2022-04-06T18:06:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [April 6, 2022, 6:09pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/4 "2022-04-06T18:09:52Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![erober69](https://avatars.discourse-cdn.com/v4/letter/e/76d3ee/32.png) [@erober69](https://discourse.psychopy.org/u/erober69)\
**Post date:** [April 6, 2022, 6:32pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/5 "2022-04-06T18:32:22Z")

</div>

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.”

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [April 6, 2022, 7:46pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/6 "2022-04-06T19:46:28Z")

</div>

What error can you see in the Browser console?

---

<div class="post-metadata">

**Author:** ![erober69](https://avatars.discourse-cdn.com/v4/letter/e/76d3ee/32.png) [@erober69](https://discourse.psychopy.org/u/erober69)\
**Post date:** [April 6, 2022, 8:14pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/7 "2022-04-06T20:14:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [April 6, 2022, 8:32pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/8 "2022-04-06T20:32:34Z")

</div>

### 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](https://gitlab.pavlovia.org/tpronk/tutorial_js_console_log)

---

<div class="post-metadata">

**Author:** ![erober69](https://avatars.discourse-cdn.com/v4/letter/e/76d3ee/32.png) [@erober69](https://discourse.psychopy.org/u/erober69)\
**Post date:** [April 6, 2022, 9:14pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/9 "2022-04-06T21:14:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [April 6, 2022, 9:41pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/10 "2022-04-06T21:41:32Z")

</div>

> [@erober69](#):
>
> 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 ?

---

<div class="post-metadata">

**Author:** ![erober69](https://avatars.discourse-cdn.com/v4/letter/e/76d3ee/32.png) [@erober69](https://discourse.psychopy.org/u/erober69)\
**Post date:** [April 6, 2022, 10:14pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/11 "2022-04-06T22:14:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [April 6, 2022, 10:18pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/12 "2022-04-06T22:18:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![erober69](https://avatars.discourse-cdn.com/v4/letter/e/76d3ee/32.png) [@erober69](https://discourse.psychopy.org/u/erober69)\
**Post date:** [April 7, 2022, 12:51pm UTC](https://discourse.psychopy.org/t/experiment-works-locally-but-pops-type-errors-in-pavlovia/28466/13 "2022-04-07T12:51:27Z")

</div>

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!
