Initialising the experiment ... but nothing more

URL of experiment: https://pavlovia.org/langlab/panreal (which should be publicly visible)

Description of the problem: When trying to pilot this experiment, both Chrome and Firefox get stuck on initialising the experiment. Using CTRL+SHIFT+J, I can see several different errors. A few errors reference a problem loading a favicon.ico (an issue I’ve seen in a few other posts), but others reference an NS_ERROR_FAILURE.

(The experiment is relatively simple. It presents a sentence followed by a picture, to which participants must respond with an arrow key. There’s not much more to it.)

I can pinpoint (maybe) the likely source of the problem. In an earlier version of this experiment, I did not have a variable initialized called condition in a code snippet in an early routine (in the Begin Experiment tab) and it ran smoothly. But since I added that variable, for counterbalancing purposes, it runs fine on PsychoPy on my Windows machine, but not online on Pavlovia. I know that this means that there is probably an issue in the JS version of the experiment.

Here’s the code snippet in Python:

import random
condition = random.choice(('a','b','c','d','e','f','g','h'))

And here it is in JS

import * as random from 'random';
var condition;
condition = random.choice(["a", "b", "c", "d", "e", "f", "g", "h"]);

If it’s of help, here is the URL for the code, html, stim, and other files, which should be public:

https://gitlab.pavlovia.org/langlab/panreal

I appreciate any help that anyone can provide, be it other forum posts to read through or a clear diagnosis that I’m missing.

Many thanks!

Please look at my crib sheet (see pinned post in online category) for information about not using import.

1 Like

Thank you! I see that! Is there a way to create a variable randomly selected from a through h? I’ll give random_character function in this post a try. Wish me luck?

Personally I just shuffle an array of options and then use the first item in the list using [0]

1 Like

I also use the function described in the post you linked i.e.

  function shuffle(a) {
      for (let i = a.length - 1; i > 0; i--) {
          const j = Math.floor(Math.random() * (i + 1));
          [a[i], a[j]] = [a[j], a[i]];
      }
      return a;
  }
  
  actors = ["A1", "A2", "A5", "A7"];
  shuffle(actors);
  actors[0] // pick the first element in the shuffled list
  
1 Like