# Stuck on "initialising the experiment"

**URL:** <https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900>\
**Category:** Online experiments\
**Tags:** pavlovia\
**Created:** [November 10, 2021, 3:48pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900 "2021-11-10T15:48:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kat](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@Kat](https://discourse.psychopy.org/u/Kat)\
**Post date:** [November 10, 2021, 3:48pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/1 "2021-11-10T15:48:52Z")

</div>

URL of experiment: [WM MA Arithmetic [PsychoPy]](https://run.pavlovia.org/kallen/wm-ma-gender-arithmetic/html)

Description of the problem: The experiment runs fine locally but then gets stuck on “initialising the experiment” when I try to run it online. I’m a complete beginner so am rather stumped with what to start playing around with for fear of breaking the local version too!

I’m struggling to find the common thread with other people who have had the same problem to see what my issue might be. I have code chunks included but as far as I can tell they aren’t importing anything, which is a suggestion I’ve seen a few times.

Not sure if the online link will work so I’ll try to copy the local experiment here:  
[WM MA Arithmetic.psyexp](https://discourse.psychopy.org/uploads/short-url/1aUxbvSsorN29ClsxtJ25VGaSWH.psyexp) (125.7 KB)

If anyone has any suggestions, that would be super useful.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [November 11, 2021, 11:30am UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/2 "2021-11-11T11:30:31Z")

</div>

Stuck on initializing means that you have a syntax error somewhere in your JS - do you have any code components? if so please share them

Thanks,  
Becca

---

<div class="post-metadata">

**Author:** ![Kat](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@Kat](https://discourse.psychopy.org/u/Kat)\
**Post date:** [November 11, 2021, 12:15pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/3 "2021-11-11T12:15:24Z")

</div>

I have quite a few so it may be easier to try and see them in the file I attached, but I will copy them here too in the hopes that helps.

Verbal recall:  
Begin routine:  
respDisplay = “”;  
maxDigits = 100;

//key logger defaults  
last\_len = 0  
key\_list =

Each frame:  
//if a new key has been pressed since last time  
if(keyResp.keys != undefined && keyResp.keys.length \> last\_len) {

```
//increment the key logger length
last_len = keyResp.keys.length

//grab the last key added to the keys list
key_list.push(keyResp.keys.pop())

//check for space
if(key_list.indexOf("space") !=-1) {
    key_list.splice(key_list.indexOf("space"), 1)
    key_list.append(key_list.indexOf(" "),1)

//check for backspace
if(key_list.indexOf("backspace") != -1) {
    key_list.splice(key_list.indexOf("backspace"), 1)
    
    //if we have at least 1 character, remove it
    if (key_list.length > 0) {
        key_list.pop();
    }
}
else
//if enter is pressed then...
if(key_list.indexOf("return") != -1) {
    //remove the enter key
    key_list.pop();
    
    //and end the trial if we have at least 2 digits
    if (key_list.length >= 2) {
        continueRoutine = false;
    }
}

//now loop through and remove any extra characters that may exist
while (key_list.length > maxDigits) {
    key_list.pop();
}

//create a variable to display
respDisplay = key_list.join("");

```

}

End routine:  
psychoJS.experiment.addData(“verbResponsef”, respDisplay);

Forward spatial recall:  
Begin experiment:  
correctcount\_3 = 0;  
sequenceLength\_3 = 3;  
incorrectCountAtLength\_3 = 0;

Begin routine:  
// initial state  
blkIndex\_3 = 0;  
nextSwitch\_3 = blockDuration;  
doingResponse\_3 = false;  
currBlock\_3 = undefined;  
dist\_min\_3 = 0;  
blockCoords\_3 = ;  
actualSequenceLength = Math.min(sequenceLength\_3, 9);

//If you got two wrong on that length, reduce length  
if ((incorrectCountAtLength\_3 === 2)) {  
sequenceLength\_3 = (sequenceLength\_3 - 1);  
incorrectCountAtLength\_3 = 0;  
}

// store ANSWER blocks as a dictionary (to switch between name/object)  
blocks\_3 = {};  
blocks\_3[‘blk1\_3’]=blk1\_3;  
blocks\_3[‘blk2\_3’]=blk2\_3;  
blocks\_3[‘blk3\_3’]=blk3\_3;  
blocks\_3[‘blk4\_3’]=blk4\_3;  
blocks\_3[‘blk5\_3’]=blk5\_3;  
blocks\_3[‘blk6\_3’]=blk6\_3;  
blocks\_3[‘blk7\_3’]=blk7\_3;  
blocks\_3[‘blk8\_3’]=blk8\_3;  
blocks\_3[‘blk9\_3’]=blk9\_3;

// Create grid of locations with jitter  
let xGrid = [-.3, 0, .3];  
let yGrid = [-.3, 0, .3];  
let locations = ;  
for (let x in xGrid) {  
for (let y in yGrid) {  
locations.push([xGrid+Math.random(2)_.1 -.05, yGrid[y]+Math.random(2)_.1 -.05]);  
}  
}

// Shuffle locations  
for (let rolls in blocks\_3) {  
locations = locations.sort(function() { return 0.5 - Math.random()});  
}  
var counter = 0; // location index

// give blocks a new set of random locations  
for (let items in blocks\_3) {  
if (blocks\_3[items].hasOwnProperty(‘pos’)) {  
blocks\_3[items].pos = locations[counter];  
counter = counter + 1;  
}  
if (blocks\_3[items].hasOwnProperty(‘fillColor’)) {  
blocks\_3[items].fillColor = new util.Color(‘white’);  
blocks\_3[items].lineColor = new util.Color(‘white’);  
}  
}

sequence\_3 = [“blk1\_3”, “blk2\_3”, “blk3\_3”, “blk4\_3”, “blk5\_3”, “blk6\_3”, “blk7\_3”, “blk8\_3”, “blk9\_3”];  
respSequence\_3 = ;

Each frame:  
if (!(doingResponse\_3) && (t \> nextSwitch\_3)) {  
if (typeof currBlock\_3 != ‘undefined’) {  
// reset color of current block  
currBlock\_3.fillColor = new util.Color(‘white’);  
currBlock\_3.lineColor = new util.Color(‘white’);  
}  
// then change current block and make that red  
if (blkIndex\_3 \>= actualSequenceLength) {  
doingResponse\_3 = true; // no more blocks to show  
} else {  
let currBlockName\_3 = sequence\_3[blkIndex\_3];  
currBlock\_3 = blocks\_3[currBlockName\_3];  
respSequence\_3.push(currBlock\_3.name);  
currBlock\_3.fillColor = new util.Color(‘red’);  
currBlock\_3.lineColor = new util.Color(‘red’);  
// track time of this change  
nextSwitch\_3 = parseFloat(nextSwitch\_3) + parseFloat(blockDuration);  
}  
blkIndex\_3 = blkIndex\_3 + 1;  
}

// all clicked?  
if (mouse\_3.clicked\_name.length \>= actualSequenceLength) {  
continueRoutine = false;  
}

// update color of clicked  
for (let blockName in mouse\_3.clicked\_name) {  
for (let eachBlock in blocks\_3) {  
if (mouse\_3.clicked\_name[blockName] == blocks\_3[eachBlock].name) {  
blocks\_3[eachBlock].fillColor = new util.Color(‘silver’);  
blocks\_3[eachBlock].lineColor = new util.Color(‘silver’);  
}  
}  
}

End routine:  
psychoJS.experiment.addData(“respSequencef”, respSequence\_3);  
psychoJS.experiment.addData(“sequenceLengthf”, actualSequenceLength);  
psychoJS.experiment.addData(“CorrectAnswerf”, sequence\_3.slice(0, actualSequenceLength));  
psychoJS.experiment.addData(“incorrectCountAtLengthf”, incorrectCountAtLength\_3);  
psychoJS.experiment.addData(“blockCoordsf”, blockCoords\_3);  
psychoJS.experiment.addData(“dist\_minf”, dist\_min\_3);  
psychoJS.experiment.addData(“Clickedf”, mouse\_3.clicked\_name);

//Is answer correct?  
if ((JSON.stringify(mouse\_3.clicked\_name) === JSON.stringify(sequence\_3.slice(0, actualSequenceLength)))) {  
sequenceLength\_3 += 1;  
incorrectCountAtLength\_3 = 0;  
} else {  
incorrectCountAtLength\_3 += 1;  
}

Backward spatial recall:  
Begin experiment:  
correctcount\_4 = 0;  
sequenceLength\_4 = 3;  
incorrectCountAtLength\_4 = 0;

Begin routine:  
// initial state  
blkIndex\_4 = 0;  
nextSwitch\_4 = blockDuration;  
doingResponse\_4 = false;  
currBlock\_4 = undefined;  
dist\_min\_4 = 0;  
blockCoords\_4 = ;  
actualSequenceLength = Math.min(sequenceLength\_4, 9);

//If you got two wrong on that length, reduce length  
if ((incorrectCountAtLength\_4 === 2)) {  
sequenceLength\_4 = (sequenceLength\_4 - 1);  
incorrectCountAtLength\_4 = 0;  
}

// store ANSWER blocks as a dictionary (to switch between name/object)  
blocks\_4 = {};  
blocks\_4[‘blk1\_4’]=blk1\_4;  
blocks\_4[‘blk2\_4’]=blk2\_4;  
blocks\_4[‘blk3\_4’]=blk3\_4;  
blocks\_4[‘blk4\_4’]=blk4\_4;  
blocks\_4[‘blk5\_4’]=blk5\_4;  
blocks\_4[‘blk6\_4’]=blk6\_4;  
blocks\_4[‘blk7\_4’]=blk7\_4;  
blocks\_4[‘blk8\_4’]=blk8\_4;  
blocks\_4[‘blk9\_4’]=blk9\_4;

// Create grid of locations with jitter  
let xGrid = [-.3, 0, .3];  
let yGrid = [-.3, 0, .3];  
let locations = ;  
for (let x in xGrid) {  
for (let y in yGrid) {  
locations.push([xGrid+Math.random(2)_.1 -.05, yGrid[y]+Math.random(2)_.1 -.05]);  
}  
}

// Shuffle locations  
for (let rolls in blocks\_4) {  
locations = locations.sort(function() { return 0.5 - Math.random()});  
}  
var counter = 0; // location index

// give blocks a new set of random locations  
for (let items in blocks\_4) {  
if (blocks\_4[items].hasOwnProperty(‘pos’)) {  
blocks\_4[items].pos = locations[counter];  
counter = counter + 1;  
}  
if (blocks\_4[items].hasOwnProperty(‘fillColor’)) {  
blocks\_4[items].fillColor = new util.Color(‘white’);  
blocks\_4[items].lineColor = new util.Color(‘white’);  
}  
}

sequence\_4 = [“blk1\_4”, “blk2\_4”, “blk3\_4”, “blk4\_4”, “blk5\_4”, “blk6\_4”, “blk7\_4”, “blk8\_4”, “blk9\_4”];  
respSequence\_4 = ;

Each frame:  
if (!(doingResponse\_4) && (t \> nextSwitch\_4)) {  
if (typeof currBlock\_4 != ‘undefined’) {  
// reset color of current block  
currBlock\_4.fillColor = new util.Color(‘white’);  
currBlock\_4.lineColor = new util.Color(‘white’);  
}  
// then change current block and make that red  
if (blkIndex\_4 \>= actualSequenceLength) {  
doingResponse\_4 = true; // no more blocks to show  
} else {  
let currBlockName\_4 = sequence\_4[blkIndex\_4];  
currBlock\_4 = blocks\_4[currBlockName\_4];  
respSequence\_4.push(currBlock\_4.name);  
currBlock\_4.fillColor = new util.Color(‘red’);  
currBlock\_4.lineColor = new util.Color(‘red’);  
// track time of this change  
nextSwitch\_4 = parseFloat(nextSwitch\_4) + parseFloat(blockDuration);  
}  
blkIndex\_4 = blkIndex\_4 + 1;  
}

// all clicked?  
if (mouse\_4.clicked\_name.length \>= actualSequenceLength) {  
continueRoutine = false;  
}

// update color of clicked  
for (let blockName in mouse\_4.clicked\_name) {  
for (let eachBlock in blocks\_4) {  
if (mouse\_4.clicked\_name[blockName] == blocks\_4[eachBlock].name) {  
blocks\_4[eachBlock].fillColor = new util.Color(‘silver’);  
blocks\_4[eachBlock].lineColor = new util.Color(‘silver’);  
}  
}  
}

End routine:  
psychoJS.experiment.addData(“respSequenceb”, respSequence\_4);  
psychoJS.experiment.addData(“sequenceLengthb”, actualSequenceLength);  
psychoJS.experiment.addData(“CorrectAnswerb”, .concat(sequence\_4.slice(0, actualSequenceLength)).reverse());  
psychoJS.experiment.addData(“incorrectCountAtLengthb”, incorrectCountAtLength\_4);  
psychoJS.experiment.addData(“blockCoordsb”, blockCoords\_4);  
psychoJS.experiment.addData(“dist\_minb”, dist\_min\_4);  
psychoJS.experiment.addData(“Clickedb”, mouse\_4.clicked\_name);

//Is answer correct?  
if ((JSON.stringify(mouse\_4.clicked\_name) === .concat(JSON.stringify(sequence\_4.slice(0, actualSequenceLength))).reverse())){  
sequenceLength\_4 += 1;  
incorrectCountAtLength\_4 = 0;  
} else {  
incorrectCountAtLength\_4 += 1;  
}

Math test:  
Begin routine:  
respDisplay\_2 = “”;  
maxDigits\_2 = 100;

//key logger defaults  
last\_len\_2 = 0  
key\_list\_2 =

Each frame:  
//if a new key has been pressed since last time  
if(keyResp\_2.keys != undefined && keyResp\_2.keys.length \> last\_len\_2) {

```
//increment the key logger length
last_len_2 = keyResp_2.keys.length

//grab the last key added to the keys list
key_list_2.push(keyResp_2.keys.pop())

//check for space
if(key_list_2.indexOf("space") !=-1) {
    key_list_2.splice(key_list.indexOf("space"), 1)
    key_list_2.append(key_list.indexOf(" "),1)
    
 //check for decimal point
if(key_list_2.indexOf("period") !=-1) {
    key_list_2.splice(key_list.indexOf("period"), 1)
    key_list_2.append(key_list.indexOf("."),1)

//check for backspace
if(key_list_2.indexOf("backspace") != -1) {
    key_list_2.splice(key_list_2.indexOf("backspace"), 1)
    
    //if we have at least 1 character, remove it
    if (key_list_2.length > 0) {
        key_list_2.pop();
    }
}
else
//if enter is pressed then...
if(key_list_2.indexOf("return") != -1) {
    //remove the enter key
    key_list_2.pop();
    
    //and end the trial if we have at least 1 digits
    if (key_list_2.length >= 1) {
        continueRoutine = false;
    }
}

//now loop through and remove any extra characters that may exist
while (key_list_2.length > maxDigits_2) {
    key_list_2.pop();
}

//create a variable to display
respDisplay_2 = key_list_2.join("");

```

}

End routine:  
psychoJS.experiment.addData(“mathResponse”, respDisplay\_2);

That is probably the least elegant way to share so if there’s a better way then let me know!  
Katie

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 11, 2021, 12:53pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/4 "2021-11-11T12:53:54Z")

</div>

The best option would be to identify the line with the error by looking at the browser console Ctrl-Shift-I in Chrome.

---

<div class="post-metadata">

**Author:** ![Kat](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@Kat](https://discourse.psychopy.org/u/Kat)\
**Post date:** [November 11, 2021, 2:12pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/5 "2021-11-11T14:12:06Z")

</div>

When I do this I get:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/e/ce29b4cea4a571e53859f617745711d72f95af1c.png)  
I guess that might mean line 2962? But then how do I get into the code to see what that is to fix it? Apologies, coding is not my forte as you can tell! I’m using Edge, but the error message is exactly the same when I do it in Chrome

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 11, 2021, 3:26pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/6 "2021-11-11T15:26:06Z")

</div>

If you click on the 2962 then you should see the line of code.

However, I suspect that the issue is an unbalanced bracket.

Possibly several …

```auto
if(key_list_2.indexOf("period") !=-1) {
    key_list_2.splice(key_list.indexOf("period"), 1)
    key_list_2.append(key_list.indexOf("."),1)

```

is missing } at the end

I avoid these kinds of errors by coding in the Python tab of an auto translate code component whenever possible. If it translates to JavaScript then the syntax should be fine.

---

<div class="post-metadata">

**Author:** ![Kat](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@Kat](https://discourse.psychopy.org/u/Kat)\
**Post date:** [November 15, 2021, 4:48pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/7 "2021-11-15T16:48:49Z")

</div>

There were a few rogue brackets that I think I’ve now removed but I still get the errors. I’ve tried clicking on the link in the error but it doesn’t do anything. The runner no longer shows any alerts (which it was before when I worked out how to get it to show me them), but the ctrl+shift+I trick shows an error with this line:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/f/2f7806916b41e105b85cb1ca463e5c63430d03fe.png)  
When I open the coder, that particular line is  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/6/065b5bacab6e5ea213910e0717cb7cd4199d3f27.png) which doesn’t seem to have any errors.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 15, 2021, 4:56pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/8 "2021-11-15T16:56:56Z")

</div>

JS code lines should end in a semi-colon ;

---

<div class="post-metadata">

**Author:** ![Kat](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@Kat](https://discourse.psychopy.org/u/Kat)\
**Post date:** [November 15, 2021, 5:39pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/9 "2021-11-15T17:39:17Z")

</div>

It still doesn’t like the same line, which is actually the “// key logger defaults” line according to the error.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 15, 2021, 5:40pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/10 "2021-11-15T17:40:21Z")

</div>

What about line 1264?

---

<div class="post-metadata">

**Author:** ![Kat](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@Kat](https://discourse.psychopy.org/u/Kat)\
**Post date:** [November 15, 2021, 5:52pm UTC](https://discourse.psychopy.org/t/stuck-on-initialising-the-experiment/25900/11 "2021-11-15T17:52:56Z")

</div>

Totally blank

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/7/37cf72c7468ad44e94638915f85a192e1c3f46d1.png)
