Error with online experiment-stuck on initilising

URL of experiment:

Description of the problem:
I created the experiment in Psychopy builder with a few code components inserted and it ran smoothly locally. I used the built-in function to convert the python script to Java script and uploaded it onto Pavlovia. I was trying to pilot the experiment and it simply doesn’t work. I looked at the errors and there are two error messages:
SyntaxError: Unexpected token ‘*’. import call expects exactly one argument.
Failed to load resource: the server responded with a status of 404 ()

I am not sure how to deal with these errors.
Thank you!

You’ve got import random in code_2 of routine A_T

You need an alternative. Have a look at my crib sheet. https://docs.google.com/document/d/13jp0QAqQeFlYSjeZS0fDInvgaDzBXjGQNe4VNKbbNHQ/edit?usp=sharing

For example, you could define randint in code_JS and then use randint(0,3) for values 0-2.

I think that the following should work

code_JS Begin Experiment

randint = function(min, maxplusone) {
  return Math.floor(Math.random() * (maxplusone - min) ) + min;
}

code_2 Begin Experiment

conditions = "ABC"
condition2=conditions[randint(0,3)]
1 Like

Hello,

Thank you so much for your help! It worked, I have another question. As I am trying to pilot it, when I get to my second task, the Stroop task, I ran into an error.


I am very confused regarding how to address this error. The task worked fine locally in its python script. Do you happen to have any advice regarding how to address this type of error? Thank you so much!

The console might give you a more specific error message.

What Begin Experiment code do you have (assuming that the syntax error is at the start)?

Hello,

I am not sure how to interpret the error message from the console(see below).

The code for the initialization of the step that ran into error is:
St_PracClock = new util.Clock();
text_7 = new visual.TextStim({
win: psychoJS.window,
name: ‘text_7’,
text: ‘default text’,
font: ‘Arial’,
units: undefined,
pos: [0, 0], height: 0.1, wrapWidth: undefined, ori: 0,
color: new util.Color(‘white’), opacity: 1,
depth: 0.0
});

text_8 = new visual.TextStim({
win: psychoJS.window,
name: ‘text_8’,
text: “Press ‘g’ if the word is in green ink.\nPress ‘y’ if the word is in yellow ink\nPress ‘r’ if the word is in red ink\nPress ‘b’ if the word is in blue ink”,
font: ‘Arial’,
units: undefined,
pos: [0, (- 0.3)], height: 0.03, wrapWidth: undefined, ori: 0,
color: new util.Color(‘white’), opacity: 1,
depth: -1.0
});

key_resp_8 = new core.Keyboard({psychoJS: psychoJS, clock: new util.Clock(), waitForStart: true});

The code for the start of the experiment is:
import { PsychoJS } from ‘./lib/core-2020.1.js’;
import * as core from ‘./lib/core-2020.1.js’;
import { TrialHandler } from ‘./lib/data-2020.1.js’;
import { Scheduler } from ‘./lib/util-2020.1.js’;
import * as util from ‘./lib/util-2020.1.js’;
import * as visual from ‘./lib/visual-2020.1.js’;
import * as sound from ‘./lib/sound-2020.1.js’;

// init psychoJS:
const psychoJS = new PsychoJS({
debug: true
});

// open window:
psychoJS.openWindow({
fullscr: true,
color: new util.Color([0, 0, 0]),
units: ‘height’,
waitBlanking: true
});

// store info about the experiment session:
let expName = ‘ArithComb’; // from the Builder filename that created this script
let expInfo = {‘participant’: ‘’, ‘session’: ‘001’};

// schedule the experiment:
psychoJS.schedule(psychoJS.gui.DlgFromDict({
dictionary: expInfo,
title: expName
}));

const flowScheduler = new Scheduler(psychoJS);
const dialogCancelScheduler = new Scheduler(psychoJS);
psychoJS.scheduleCondition(function() { return (psychoJS.gui.dialogComponent.button === ‘OK’); }, flowScheduler, dialogCancelScheduler);

// flowScheduler gets run if the participants presses OK
flowScheduler.add(updateInfo); // add timeStamp
flowScheduler.add(experimentInit);
flowScheduler.add(GInsRoutineBegin());
flowScheduler.add(GInsRoutineEachFrame());
flowScheduler.add(GInsRoutineEnd());
const DCILoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(DCILoopBegin, DCILoopScheduler);
flowScheduler.add(DCILoopScheduler);
flowScheduler.add(DCILoopEnd);
const DCPLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(DCPLoopBegin, DCPLoopScheduler);
flowScheduler.add(DCPLoopScheduler);
flowScheduler.add(DCPLoopEnd);
flowScheduler.add(DC_BrkRoutineBegin());
flowScheduler.add(DC_BrkRoutineEachFrame());
flowScheduler.add(DC_BrkRoutineEnd());
const DCTLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(DCTLoopBegin, DCTLoopScheduler);
flowScheduler.add(DCTLoopScheduler);
flowScheduler.add(DCTLoopEnd);
flowScheduler.add(GinsRoutineBegin());
flowScheduler.add(GinsRoutineEachFrame());
flowScheduler.add(GinsRoutineEnd());
const StILoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(StILoopBegin, StILoopScheduler);
flowScheduler.add(StILoopScheduler);
flowScheduler.add(StILoopEnd);
const StPLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(StPLoopBegin, StPLoopScheduler);
flowScheduler.add(StPLoopScheduler);
flowScheduler.add(StPLoopEnd);
const STTLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(STTLoopBegin, STTLoopScheduler);
flowScheduler.add(STTLoopScheduler);
flowScheduler.add(STTLoopEnd);
const StnILoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(StnILoopBegin, StnILoopScheduler);
flowScheduler.add(StnILoopScheduler);
flowScheduler.add(StnILoopEnd);
const StnPLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(StnPLoopBegin, StnPLoopScheduler);
flowScheduler.add(StnPLoopScheduler);
flowScheduler.add(StnPLoopEnd);
const StnTLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(StnTLoopBegin, StnTLoopScheduler);
flowScheduler.add(StnTLoopScheduler);
flowScheduler.add(StnTLoopEnd);
flowScheduler.add(GIns_ARoutineBegin());
flowScheduler.add(GIns_ARoutineEachFrame());
flowScheduler.add(GIns_ARoutineEnd());
const AILoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(AILoopBegin, AILoopScheduler);
flowScheduler.add(AILoopScheduler);
flowScheduler.add(AILoopEnd);
const APLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(APLoopBegin, APLoopScheduler);
flowScheduler.add(APLoopScheduler);
flowScheduler.add(APLoopEnd);
flowScheduler.add(A_brkRoutineBegin());
flowScheduler.add(A_brkRoutineEachFrame());
flowScheduler.add(A_brkRoutineEnd());
const ATLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(ATLoopBegin, ATLoopScheduler);
flowScheduler.add(ATLoopScheduler);
flowScheduler.add(ATLoopEnd);
flowScheduler.add(ThkRoutineBegin());
flowScheduler.add(ThkRoutineEachFrame());
flowScheduler.add(ThkRoutineEnd());
flowScheduler.add(quitPsychoJS, ‘’, true);

Thank you so much for your help! Really appreciate it!

That looks like raw JS code. Please could you show the Python+JS code components you’ve added?

My apology. I did not add any code component for that part of the task which ran into error (St_Prac). I added a python+JS code component for the first part of the task to give feedback:

if not key_resp_2.keys:
msg2=“Failed to respond”
elif key_resp_2.corr:
msg2=“Correct!”
else:
msg=“Oops! That was wrong”

The feedback worked fine.

I also have the other code component that you have previously helped me to revise. But that is it.

If you are sure that the St_Prac routine is the one creating the error and it doesn’t have a code component, perhaps you have some Python code in one of the components.

Hmmm, I will check again. I just uploaded my separate version of Stroop task onto pavlovia to pilot and I ran into the same error. This task does not contain any code component and iti s a replica of the part of the task that ran into error. I am a bit confused here, but I guess I will see if there is anything else that could’ve caused the error or if it could’ve be my computer or something. Anyway, thank you so much for your help!

Check Use PsychoPy Version is blank

That just took me an hour to solve this morning despite already being in my crib sheet

1 Like

Thank you so much for your help. I am sorry that it took you so long time to help me. I am sorry but I am a bit confused, how do I resolve that issue. Very thankful for your help.

Sorry I meant that I spent an hour trying to solve a similar issue in a different experiment.

In PsychoPy go to your experiment options (the same page as where you set participant and version). Is there anything in the Use PsychoPy Version field?

1 Like

This is the current field. Should I set it to a certain version?

No, it means you don’t have the same problem unfortunately.

What are the last messages in your console before it gets to the errors?

1 Like

It looks like this way.

Cool. Please could you tell me more about the setting and use of the two dictionaries and variables listed (Trial, StInstruction, Number, Color, StFb)?

1 Like

StInst.xlsx (8.9 KB)
StPrac.xlsx (10.4 KB)

Hello,

Thank you again for your help.

The StInstruction consists of two elements, a keyboard and a text. There is a loop surrounding it such that the keyboard element takes the information from the StInst excel file. The keyboard allows any key to be entered.

After the instruction, it comes to the practice trials where there will be two text elements, one text element take information from the StPrac excel file. The color and the content of the text is also determined by the information extracted from the StPrac excel file. The other text element is constant throughout. The keyboard only allows four keys to be entered (‘b’,‘y’,‘g’,’r’).

As for the StFb, the trial include a text component and a keyboard component where the text is determined by the element from the StPrac excel file and the keyboard allows any entry of the key to end the routine.

Please let me know if this is the information that is needed. I apologize for bombarding you with the information. Thank you again for your help.


I can’t see anything wrong there. Do you have any other code components apart from the feedback you mentioned earlier?

1 Like

Not really. I only have code components for the feedback(which worked fine) and the code component that you helped me revised.

Hello, I am sorry to bother you again, but it appears that this code you provided ran into an error. I am a complete newbie to javascript and coding in general, I am not sure where it went wrong, can you help me? Thank you so much!