Infinite initializing experiment

URL of experiment: https://run.pavlovia.org/MarkovYA/animalsearch3/html/

Description of the problem: I tried for several times to create new project, but I still stuck on the initializing experiment screen. I am using v2020.1.3. Thanks!

When I open the web debugging console in chrome it says there’s a syntax error in your code because of the line
import * as random from 'random';
apparently that needs to be at the top of the file in JS. I guess we need to find a way that additional JS modules can be imported without breaking studies! :-/

Thank you! I fixed this by deleting all auto translated code and replacing it by my JS script. I have random module in Py code and it is translated into this in JS as import * as random from ‘random’;.

OK. thanks for letting me know. Out of interest, did you then move the code to another spot, or did you not need the import statement at all in your final version?

I had this in Python in code block
import random z=randint(1,32)
And instead of this I just wrote this in JS:

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}
z=getRandomInt(1,32)

Actually when I start PsychoPy it is sometime ruins my JS code in code block and put autotranslated code instead.

2 Likes

Hi both @Yura_Markov @jon , I think have the same problem. This is what I got in Stdout:

Alert 4210:JavaScript Syntax Error in ‘Begin JS Experiment’ tab. See ‘Line 1: Unexpected token’ in the ‘Begin JS Experiment’ tab.

8415.2480 ERROR Line 111: Unexpected token in Pri_word.js
8416.0981 ERROR Line 103: Unexpected token in Pri_word-legacy-browsers.js

This is the error line

inicodeClock = new util.Clock();

Below this line are these two lines

import * as random from 'random';
import * as xlrd from 'xlrd';

Do you know how to fix this? thanks a lot!
URL of experiment: https://run.pavlovia.org/xiaotong/concurrent-task/html

I have same problem here and get stuck here for several days. so frustrating…
I am wondering whether we can use ‘import’ in JS.

@Ethan @Xiaotong I think that you can’t use import random in JS. So, it is better to use functions that I described higher. You just need to change auto PY->JS to both and manually write correct code

1 Like

Yes, although importing libs is possible in JS we haven’t yet exposed an entry point high enough in the script to allow you to do it. We’’ work on that for a future version but in the meantime @Yura_Markov solution is the one

1 Like

Is this the only solution? I’ve tried this solution and still receive the same error.

Is this the only solution? I’ve done this but still receive an error following a read of a wordlist csv in a loop.

I’m having the same issue as above, details in post here: Error syncing from builder

My confusion is that I have not written any code manually as the above posts seem to indicate had caused this issue. I just used point and click in builder.

Like @memlab my issue seems related to a csv list of files used as the condition in a loop.

@jon @Yura_Markov

Sorry, I’m not quite understanding the solution.

Here is the link to the my experiment: Zared / Diss - Pilot Sentence Norming · GitLab (pavlovia.org)

I’m having this same problem for seemingly the same reason. I had a code component to create and randomly shuffle some lists as part of my complex stimulus randomization scheme.

I also used autotranslate Py-JS. I’m quite proficient with Python, know 0 with JS and this is my first rodeo uploading to Pavlovia.

I put the following in Begin Experiment:

fillArr = np.random.choice(range(5,62), size = 21,replace = False)
firFiveFill = [i for i in range(5)]
fill = fillArr.tolist()
mystArr = np.random.choice(range(62,157), size = 32,replace = False)
myst = mystArr.tolist()
order = fill+myst
random.shuffle(order)
stories = firFiveFill + order

I put in import random Before Experiment.

Is the error with the random choice function or with the import random?

I am experiencing the same problem, when I look at the line of code the error message mentions I see import statements but none of it is code I wrote, it’s like:
“import { PsychoJS } from ‘./lib/core-2020.2.js’;
import * as core from ‘./lib/core-2020.2.js’;
import { TrialHandler } from ‘./lib/data-2020.2.js’;
import { Scheduler } from ‘./lib/util-2020.2.js’;
import * as visual from ‘./lib/visual-2020.2.js’;
import * as sound from ‘./lib/sound-2020.2.js’;
import * as util from ‘./lib/util-2020.2.js’;”

Do you think that these are also causing problems?