Randomizing Not Working

URL of experiment: Sign in · GitLab

This is pretty much my last hope on here. I’ve been trying to solve this for about three months, so any help is valued.

My experiment tests participants’ ability to classify Mandarin words by tone. There are seven sets of words, and each set has three word variants. I attached a spreadsheet of a sample conditions file. wordList.xlsx (9.9 KB)

Referring to the conditions file, let’s call each row a “set” and columns B, C, and D tones 1, 2, and 3. Each of the three “tones” is an audio file that should play using the audio component in the builder. For the experiment, I need each set (cai, ba, ying, etc.) to play in full (Tone 1, Tone 2, and Tone 3) before moving to the next set. But I would like the order in which the tones of each set play to be random (i.e., ba1, ba3, ba2 for one participant but maybe ba3, ba1, ba2 for another participant).

With help from other users a while back, I have a code for the builder that works perfectly; however, when I uploaded it to Pavlovia, it will not work correctly. The code is:

if ((trials.thisTrialN === 0)) {
    tones = [Tone1, Tone2, Tone3];
current_tone = tones.pop();

In my audio component, I have the “sound” as a variable $current_tone and it is set to “every repeat”.

The order of the sets is always random, which is good! It’s the tones within each set that are not correct. What happens on Pavlovia is sometimes the set plays as “Tone1, Tone1, Tone1”, when it should always be some (random) variation of “Tone1, Tone2, Tone3” in whatever order. Sometimes all tones play correctly, but usually one of the tones plays more than once and not all tones are played.

Here is what I have tried:

  • I have checked to make sure that the variables are labelled correctly in the audio properties and that it is set every repeat.
  • I’ve also made sure my loop is set to random
  • I have added the following, per the Crib sheet, to my “Begin Experiment” tab on the code sequence:
tones = [];
shuffle = util.shuffle;
  • I was told that .thisN doesn’t work on Pavlovia, so I tried using a dummy variable (Idx = 0) instead. The code became the following:
if ((Idx == 0)) {
    tones = [Tone1, Tone2, Tone3];
current_tone = tones.pop()

  • I tried incrementing the dummy variable using Idx +=1 at the end of the loop, which worked for the first word set, but for all other sets, there are just “beeps” that play instead of my audio files.

Please feel free to reach out with any questions or clarification. I’m all out of ideas, and I really don’t know how to proceed. The link to my study is at the top of the page.

THANK YOU to anyone who is able to to take the time and help me out.


you might want to check the autotranslated (?) javascript code. While it is .pop() in PsychoPy, it is .shift() in JavaScript.

Best wishes Jens

Thanks for the response. I’ve actually tried shift() and had no luck with that either.

Hello jbf27237,

well your experiment is quite large, so I can’t really pinpoint where your randomization does not work as intended. Do you have a toy-version of your experiment?

Best wishes Jens


I tried to implement a toy example using two loops. I hope that is what you wanted to achieve. I have not checked it on-line yet.

StimulusList.xlsx (9.6 KB) Tone.psyexp (9.7 KB) Tone.xlsx (8.4 KB)

Best wishes Jens

@JensBoelte, you are my hero. This is working. Thank you SO MUCH!