Help with: reference error: shuffle is not defined

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

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

Have you looked at my crib sheet regarding code_JS

However, this might not be needed in 2021.2.2

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?

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

can confirm not needed in 2021.2.2 :slight_smile:

do you know what might be causing the error? :slight_smile:

I think that your issue is with this line.

 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:

 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?

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

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

Thanks!

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 (146.9 KB)

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)?

Yes of course Wakecarter, here is the code:

Practice trials (there are 45)
Digits
Screen Shot 2021-08-12 at 9.52.19 pm
Screen Shot 2021-08-12 at 9.52.44 pm

Real trials (there are 900)
Digits


Interstimulus intervals (same for practice and real trials)

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:

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.

Thank you for your suggestions Wakecarter.

I changed code_3 and code_4:


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

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.

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

1 Like

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]
I had a look through your past responses to this error but can’t figure it out.


“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
cd sart
touch README.md
git add README.md
git commit -m “add README”
git push -u origin master

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

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