# Experiment working offline fine but giving error in online mode

**URL:** <https://discourse.psychopy.org/t/experiment-working-offline-fine-but-giving-error-in-online-mode/12897>\
**Category:** Online experiments\
**Tags:** online\
**Created:** [April 30, 2020, 11:55am UTC](https://discourse.psychopy.org/t/experiment-working-offline-fine-but-giving-error-in-online-mode/12897 "2020-04-30T11:55:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![xai](https://avatars.discourse-cdn.com/v4/letter/x/b9bd4f/32.png) [@xai](https://discourse.psychopy.org/u/xai)\
**Post date:** [April 30, 2020, 11:55am UTC](https://discourse.psychopy.org/t/experiment-working-offline-fine-but-giving-error-in-online-mode/12897/1 "2020-04-30T11:55:36Z")

</div>

URL of experiment: [https://pavlovia.org/jaycbcs/esst\_2](https://pavlovia.org/jaycbcs/esst_2)

Description of the problem: working fine in online mode

when i am running it is giving an error that

" **ReferenceError: win is not defined**"

Thanks in advance…

any suggestion.

Thank You

---

<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 30, 2020, 12:12pm UTC](https://discourse.psychopy.org/t/experiment-working-offline-fine-but-giving-error-in-online-mode/12897/2 "2020-04-30T12:12:51Z")

</div>

That’s an easy one. You need to define win

Check my crib sheet

> **[PsychoPy Python to Javascript crib sheet](https://docs.google.com/document/d/13jp0QAqQeFlYSjeZS0fDInvgaDzBXjGQNe4VNKbbNHQ/edit?usp=sharing)**
>
> PsychoPy Python to Javascript crib sheet PsychoPy 2020 has an automatic Python to Javascript translation tool. This document contains information about code that is not translated correctly. The change permissions: “view code”, then “settings -\>...

I would recommend having a JS code window in the first routine with (as a minimum):

```auto
thisExp=psychoJS.experiment;
win=psychoJS.window;

```

Best wishes,

Wakefield

---

<div class="post-metadata">

**Author:** ![xai](https://avatars.discourse-cdn.com/v4/letter/x/b9bd4f/32.png) [@xai](https://discourse.psychopy.org/u/xai)\
**Post date:** [April 30, 2020, 12:50pm UTC](https://discourse.psychopy.org/t/experiment-working-offline-fine-but-giving-error-in-online-mode/12897/3 "2020-04-30T12:50:40Z")

</div>

Thanks a lot. it really helped and some other issues.

Thank You

---

<div class="post-metadata">

**Author:** ![xai](https://avatars.discourse-cdn.com/v4/letter/x/b9bd4f/32.png) [@xai](https://discourse.psychopy.org/u/xai)\
**Post date:** [April 30, 2020, 8:42pm UTC](https://discourse.psychopy.org/t/experiment-working-offline-fine-but-giving-error-in-online-mode/12897/4 "2020-04-30T20:42:48Z")

</div>

sorry to bug you again…

i am using shuffle function in my experiment.

i am adding this text in my code with

thisExp=psychoJS.experiment;  
win=psychoJS.window;

shuffle = function (a) {  
return util.shuffle(a);  
}

giving error message as shuffle function is not defined  
Thank You

---

<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 30, 2020, 10:22pm UTC](https://discourse.psychopy.org/t/experiment-working-offline-fine-but-giving-error-in-online-mode/12897/5 "2020-04-30T22:22:37Z")

</div>

Have you added the shuffle function at Javascript to the first Begin Experiment block (or at least in Begin Experiment before you try to use it)?

For example, I have a starting code block that looks like this:

 ![code_js](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/8/1891f25b7451194b0c6d190dd0f47d76f7061f7c.png)

---

<div class="post-metadata">

**Author:** ![xai](https://avatars.discourse-cdn.com/v4/letter/x/b9bd4f/32.png) [@xai](https://discourse.psychopy.org/u/xai)\
**Post date:** [May 1, 2020, 6:18am UTC](https://discourse.psychopy.org/t/experiment-working-offline-fine-but-giving-error-in-online-mode/12897/6 "2020-05-01T06:18:08Z")

</div>

Thank you for replying,

Did same thing in first routine  
first code section.

giving error message again:

**ReferenceError: shuffle is not defined**  
running online.

When i am compiling in builder mode and it is generating code, this piece of code is not appearing there.  
"thisExp=psychoJS.experiment;  
win=psychoJS.window;  
"  
This was working when putting in the py (code type).

 ![code](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/0/0060c881b813aa2b51fa626b47f79c6ab8335aa3.jpeg)

Thank You

---

<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:** [May 1, 2020, 6:46am UTC](https://discourse.psychopy.org/t/experiment-working-offline-fine-but-giving-error-in-online-mode/12897/7 "2020-05-01T06:46:49Z")

</div>

Three questions

Are you using the latest version of PsychoPy?

Is your “Use PsychoPy version “ field blank?

What do you mean by compile? I use the sync button to upload.

---

<div class="post-metadata">

**Author:** ![xai](https://avatars.discourse-cdn.com/v4/letter/x/b9bd4f/32.png) [@xai](https://discourse.psychopy.org/u/xai)\
**Post date:** [May 1, 2020, 7:50am UTC](https://discourse.psychopy.org/t/experiment-working-offline-fine-but-giving-error-in-online-mode/12897/8 "2020-05-01T07:50:22Z")

</div>

Are you using the latest version of PsychoPy?  
Latest PsychoPy v2020.1.3

Is your “Use PsychoPy version “ field blank?  
How to get this specification, please let me know.

What do you mean by compile? I use the sync button to upload.  
I compile in builder mode then sync it for [https://pavlovia.org/](https://pavlovia.org/)

Thank You
