# Help with: reference error: shuffle is not defined

**URL:** <https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446>\
**Category:** Online experiments\
**Tags:** randomization, online, pavlovia\
**Created:** [August 8, 2021, 6:06am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446 "2021-08-08T06:06:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 8, 2021, 6:06am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/1 "2021-08-08T06:06:34Z")

</div>

Hi all,

I keep getting the error “reference error: shuffle is not defined” when I try running my psychopy experiment on Pavlovia, but it works fine offline. The experiment involves randomly presented the digits 1-9. The size of the font they’re presented in is also randomised.

The URL is: [https://pavlovia.org/run/belindam/new-project](https://pavlovia.org/run/belindam/new-project)

I’m not sure if I have given enough information to describe the problem, but would really appreciate any insight or help. I have psychopy builder (v2021.1.4). Does anyone know how to fix this?

Thanks in advance,  
Belinda

---

<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:** [August 8, 2021, 7:25am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/2 "2021-08-08T07:25:11Z")

</div>

Have you looked at my crib sheet regarding code\_JS

However, this might not be needed in 2021.2.2

---

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 8, 2021, 8:02am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/3 "2021-08-08T08:02:24Z")

</div>

Thank you for your reply wakecarter!

I had a look at your crib sheet and did these steps to add a JavaScript only code component to my first routine:

1. I added a code component called code\_JS in my experimenter’s first routine (this is one of my slides with instructions)
2. I switched it from Auto-\>JS to JS
3. I copied the code “shuffle = util.shuffle;” into the begin experiment page

When I ran the experiment, I got a new error: “TypeError: sizes.pop is not a function”. I’m not sure if this is a similar issue as the shuffle one, in which I need to add another JS code?

---

<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:** [August 8, 2021, 5:01pm UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/4 "2021-08-08T17:01:13Z")

</div>

> [@Belinda](#):
>
> sizes.pop is not a function”

sizes.pop() should be fine if sizes is a list.

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [August 8, 2021, 7:03pm UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/5 "2021-08-08T19:03:13Z")

</div>

can confirm not needed in 2021.2.2 🙂

---

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 9, 2021, 8:22am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/6 "2021-08-09T08:22:39Z")

</div>

do you know what might be causing the error? 🙂

---

<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:** [August 9, 2021, 9:21am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/7 "2021-08-09T09:21:07Z")

</div>

I think that your issue is with this line.

```auto
 sizes = ([1.7, 2.5, 3.3, 3.5, 4.2] * 10);

```

You can’t create a matrix this way. Personally I would just do:

```auto
 sizes = [1.7, 2.5, 3.3, 3.5, 4.2,1.7, 2.5, 3.3, 3.5, 4.2,1.7, 2.5, 3.3, 3.5, 4.2,1.7, 2.5, 3.3, 3.5, 4.2,1.7, 2.5, 3.3, 3.5, 4.2,1.7, 2.5, 3.3, 3.5, 4.2,1.7, 2.5, 3.3, 3.5, 4.2,1.7, 2.5, 3.3, 3.5, 4.2,1.7, 2.5, 3.3, 3.5, 4.2,1.7, 2.5, 3.3, 3.5, 4.2];

```

Did you remove the definition of shuffle again?

---

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 9, 2021, 12:21pm UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/8 "2021-08-09T12:21:27Z")

</div>

Hmm unfortunately that hasn’t fixed it. What do you mean about removing the definition of shuffle?

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [August 11, 2021, 5:03pm UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/9 "2021-08-11T17:03:47Z")

</div>

> [@Belinda](#):
>
> “TypeError: sizes.pop

Please could you also show us the code where you implement that pop line?

Thanks!

---

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 12, 2021, 4:18am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/10 "2021-08-12T04:18:03Z")

</div>

Hi Becca,

Here is a bit of background on the experiment for context:

- I have implemented the pop line in 2 different routines (the first one is a practice trial block of 45 trials and the second is the longer block of 900 trials).
- The trials are randomised so they are between 1.3 - 1.7 seconds in duration and the stimuli is between 1.7 and 4.2cm in height  
[SART.psyexp](https://discourse.psychopy.org/uploads/short-url/weVvuw6QHHc7wJoXCEoM9kGXZRE.psyexp) (146.9 KB)

---

<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:** [August 12, 2021, 8:19am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/11 "2021-08-12T08:19:44Z")

</div>

Please could you post the code (copy and paste and/or screenshot) here so we don’t have to spend time downloading and searching your Builder file (which is useful for when viewing the code here isn’t sufficient)?

---

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 12, 2021, 12:02pm UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/12 "2021-08-12T12:02:46Z")

</div>

Yes of course Wakecarter, here is the code:

**Practice trials (there are 45)**  
Digits  
 ![Screen Shot 2021-08-12 at 9.52.19 pm](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/b/1b53bd17736ff096695f805288663218c90ce3f5.png)  
 ![Screen Shot 2021-08-12 at 9.52.44 pm](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/5/452347e4c9a55442fa2a1be795f9896bb9ad5387.png)

---

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 12, 2021, 12:03pm UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/13 "2021-08-12T12:03:23Z")

</div>

**Real trials (there are 900)**  
Digits

 ![Screen Shot 2021-08-12 at 9.55.54 pm](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/2/3228a9b2ba5c729ff0ae3c8f92ebafbbac0b1328.png)  
 ![Screen Shot 2021-08-12 at 9.56.24 pm](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/3/2369a7a9b81cfb863517096820e47c4a4c512fe6.png)

---

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 12, 2021, 12:04pm UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/14 "2021-08-12T12:04:06Z")

</div>

Interstimulus intervals (same for practice and real trials)

 ![Screen Shot 2021-08-12 at 9.56.14 pm](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/3/d30a5fe37a4c81e7ba454426c2827aeb840acf29.png)

---

<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:** [August 12, 2021, 12:56pm UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/15 "2021-08-12T12:56:28Z")

</div>

code\_3 and code\_4 are both defining times in Begin Experiment, but you are still using matrix multiplication which won’t work in JS.

Since you might not want to copy paste 100 times how about this:

```auto
times = []
for Idx in range(100)
     times.append(1.3)
     times.append(1.4)
     times.append(1.5)
     times.append(1.6)
     times.append(1.7)

print('Preshuffle',times[0])
shuffle(times)
print('Postshuffle',times[0])

```

Then check the Browser console.

For append to work you’ll need the latest version of PsychoPy or to define it in code\_JS as per my crib sheet.

---

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 14, 2021, 2:06am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/16 "2021-08-14T02:06:25Z")

</div>

Thank you for your suggestions Wakecarter.

I changed code\_3 and code\_4:

 ![Screen Shot 2021-08-14 at 11.54.52 am](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/5/35f69974ed3e8155b9fb12e32e99c37dbb2e88da.png)  
 ![Screen Shot 2021-08-14 at 11.55.12 am](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/4/4479e1d0b888b8ba25c6286040ffc89d60b4d05a.png)

However, I got this error code:

> Alert 4205:Python Syntax Error in ‘Begin Experiment’ tab. See 'for Idx in range(100)  
> ’ on line number 2 of the ‘Begin Experiment’ tab.  
> For further info see [4205: Probable syntax error detected in your Python code — PsychoPy v2023.2.3](https://psychopy.org/alerts/4205.html)  
> Alert 4205:Python Syntax Error in ‘Begin Experiment’ tab. See 'for Idx in range(100)  
> ’ on line number 2 of the ‘Begin Experiment’ tab.  
> For further info see [4205: Probable syntax error detected in your Python code — PsychoPy v2023.2.3](https://psychopy.org/alerts/4205.html)

I’m not sure how to view the browser console (I have a mac and tried control-option-j but it didn’t work) and I also updated my psychopy to v2021.2.3.

---

<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:** [August 14, 2021, 9:14pm UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/17 "2021-08-14T21:14:31Z")

</div>

The syntax error in your screenshots is because you are missing the colon after range(100) when defining the loops.

---

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 15, 2021, 4:20am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/18 "2021-08-15T04:20:39Z")

</div>

Oh yes that works now! I’m just trying to run the project through Gitlab now. I’m having trouble figuring out how to do this.  
I uploaded the files to the repository but am getting the 403 forbidden error when I try running it through Pavlovia. This is the link: [Sustained attention to response task [PsychoPy]](https://run.pavlovia.org/belindam/sart/)  
I had a look through your past responses to this error but can’t figure it out.

 ![Screen Shot 2021-08-15 at 2.21.25 pm](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/f/ef163a3ad4f80da9864bcc1f9f4cf01efef7985e.png)  
_“Exp\_stimuli” and “Practice\_stim\_short” are the 2 excel spreadsheets that psychopy reads. “Version\_5” is my psychopy file_

Note: the deleted file was something was something I uploaded but I don’t think it’s needed?

> git clone [Sign in · GitLab](https://gitlab.pavlovia.org/belindam/sart.git)  
> cd sart  
> touch README.md  
> git add README.md  
> git commit -m “add README”  
> git push -u origin master

---

<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:** [August 15, 2021, 7:27am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/19 "2021-08-15T07:27:53Z")

</div>

Do you have multiple PsychoPy psyexp files in the same folder?

---

<div class="post-metadata">

**Author:** ![Belinda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/belinda/32/30623_2.png) [@Belinda](https://discourse.psychopy.org/u/Belinda)\
**Post date:** [August 15, 2021, 9:37am UTC](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446/20 "2021-08-15T09:37:59Z")

</div>

If you mean the folder on my computer, then no. I just have those same 3 files there

[Next page](https://discourse.psychopy.org/t/help-with-reference-error-shuffle-is-not-defined/24446.md?page=2)
