Online experiment stuck on "initializing the experiment..."

URL of experiment: WM Task v1 [PsychoPy]

Description of the problem: I have created an experiment on version 2020.2.0 that works perfectly online but when I try to run the study online with Pavlovia, the screen gets stuck on “initializing the experiment…”
I have attached the generated files in a zip (excluding the videos), and would greatly appreciate any help with getting it to work!
wm task.zip (38.2 KB)

Hi there, I’m just looking from the error message on the console and it seems like at one point you’re importing the library random and then using shuffle? You don’t need to do this as shuffle is readily available in psychopy and will automatically translate to psychoJS

Hi,

Thanks for your reply. This is the code I currently have in my Begin Experiment tab of the first Routine

import random

Videos = ["Ethics_1sec_0-5_ped.mp4","Ethics_1sec_1-5_ped.mp4",
    "Ethics_1sec_5-0_ped.mp4","Ethics_1sec_5-1_ped.mp4",
    "Ethics_2sec_0-5_ped.mp4","Ethics_2sec_1-5_ped.mp4",
    "Ethics_2sec_5-0_ped.mp4","Ethics_2sec_5-1_ped.mp4",
    "Ethics_3sec_0-5_ped.mp4","Ethics_3sec_1-5_ped.mp4",
    "Ethics_3sec_5-0_ped.mp4","Ethics_3sec_5-1_ped.mp4",
    "NoPed_Catch1.mp4","NoPed_Catch2.mp4","NoPed_Catch3.mp4",
    "NoPed_Catch4.mp4"] 
random.shuffle(Videos)

pairlist = [("D","D","z"), ("T","T","z"), ("G","G","z"), ("I","I","z"), 
    ("E","E","z"), ("J","J","z"), ("F","F","z"), ("P","P","z"), 
    ("Y","K","slash"), ("B","T","slash"), ("U","N","slash"), ("Z","K","slash"),
    ("K","V","slash"), ("N","F","slash"), ("V","L","slash"), ("O","S","slash")]

random.shuffle(pairlist)
firststim = []
secondstim = []
corrAns = []

for i in pairlist:
    firststim.append(i[0])
    secondstim.append(i[1])
    corrAns.append(i[2])

The Code Type is set to ‘Auto->JS’. I need the videos and pairlists to be randomly selected for each trial. There are 16 trials in total (each video and pairlist randomly appears once in the experiment).

Could you please guide me with changing it appropriately because it works fine offline but doesn’t load online?

From the Console, it throws line 102 as an error:

Uncaught SyntaxError: Unexpected token ‘*’

I have the following on line 102 of my .js file: import * as random from 'random';
The * seems to have been added when converting from Python to JavaScript.

You can’t import the random library in JS.

https://psychopy.org/online/psychoJSCodingDebugging.html

Yes following from @wakecarter , the * indicates that the library is not recognised. I believe if you remove the line

import random

and remove random. from the lines

#original
random.shuffle(Videos)
random.shuffle(pairlist)

#edited
shuffle(Videos)
shuffle(pairlist)

And resync, it should work. Once you’ve removed these, the JS counterpart should say

util.shuffle

Hi @wakecarter and @suelynnmah,

Thanks for your suggestions.
I decided to setup the experiment on another computer that has the latest version v2022.1.4 since it seems like the ‘Auto->JS’ function doesn’t work too well in the older versions, and removed the ‘random’ as suggested, but I’m still unable to run it online and get errors in my Console that say: Failed to load resource: the server responded with a status of 404 ()

Do you have any ideas on what could be causing this?
wm-armoury.psyexp (31.0 KB)
wm-armoury_lastrun.py (31.3 KB)

Hello @wakecarter and others,

I am having a similar issue, I think. My psychopy file runs fine locally*, but when I synced to pavlovia and tried to run it online, it doesn’t go past “initializing the experiment.”

*I do get an ‘alert’ message as follows:

“Alert 4210:JavaScript Syntax Error in ‘Begin JS Routine’ tab. See ‘Line 5: Unexpected token ILLEGAL’ in the ‘Begin JS Routine’ tab.”

I have several code components throughout the experiment, but I don’t see a javascript error in any of them. I am also not sure where the “Line 5” is that I am supposed to look at. Line 5 of the .js file is an import statement (not altered by me).

Based on previous posts, I am guessing that the issue is some kind of js issue–I have done something that works in python but not in js? But I don’t know what it is or how to find it. I have not added any import statements.

expt is here:Pavlovia

Thanks in advance.

Hi @pkalra, when you are stuck at “initializing experiment” you can open the console (Firefox: ctrl + shift + K, Chrome: ctrl + shift + J). There you will see what is actually going wrong with the initialization of the experiment. I wonder, why it runs fine locally when you get this error. Line 5 does refer to some “Begin routine” tab, so not the js script in total. If you want others to have a look at your experiment you have to make it public.

1 Like

Thanks very much! I am using chrome but nothing happened when I tried ctrl+shift+J. However, I read this (Thomas Pronk / tutorial_js_console_log · GitLab) and went to “developer tools” and was able to get this error message, so at least that confirms the issue (or at least the first issue).

So that’s a first step! Thanks.

Also, I can’t find where to make the experiment public? Do I need to go into github and make the repo public from there? Or is there somewhere within the pavlovia interface?
thanks.

Yes, it’s in the gitlab repo settings.

In the console, you can click on the .js on the right-hand side of the error message and it will take you directly to the line where the error is.

1 Like