psychopy.org | Reference | Downloads | Github

Online Study Error Fatal Error Unknown

URL of experiment: Sign in · GitLab

Description of the problem: I am getting this error during running my study that seems to be caused by the builder’s audio file. The error is Unspecified JavaScript error, when I add breakpoints it seems the there is an issue with disconnecting the audio file? If I remove the audio file I still have issues where it seems my variables aren’t being created although I declare them.

Sorry I am pretty new to python/javascript and could be doing something totally wrong. Additionally it seems that my experiments needs to create a new project every time I need to sync. Sorry for the lack of explicit information, but I cannot find anyone else with this issue.

Also here is a link to the actual study: https://run.pavlovia.org/smmaul09/test3/html/?__pilotToken=eccbc87e4b5ce2fe28308fd9f2a7baf3&__oauthToken=808599e87c66a333246f28516293e0616cc1c6685f6c9444d128938024aa1532.

Photo:

Hi.

Please could you show your Python/JavaScript Begin Experiment code blocks (and perhaps your audio components if you think they may be the issue)?

Best wishes,

Wakefield

Here is my Begin Experiment Blocks

#Start

/////GLOBAL CODE////

//JAVASCRIPT FOR PSYCHOPY CGT

    // add-on: list(s: string): string[]
    function list(s) {
        // if s is a string, we return a list of its characters
        if (typeof s === 'string')
            return s.split('');
        else
            // otherwise we return s:
            return s;
    }

////Functions////
//Sampling function (choice())
Array.prototype.sample = function(){
return this[Math.floor(Math.random()*this.length)];
}

function fillArray(value, len) {
var arr = ;
for (var i = 0; i < len; i++) {
arr.push(value);
}
return arr;
}

//Range array
function range(size, startAt = 0) {
return […Array(size).keys()].map(i => i + startAt);
}

//Shuffling stuff
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;

// While there remain elements to shuffle…
while (0 !== currentIndex) {

// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;

}

return array;
}

////Variables////
var array_correct, array_desc, array_group, array_image, array_redprob, bankrupt, bet_asc, bet_des, num_items, range_items, reps, seq, seq_count, star_pos, starting_score, study_trial, total_score;
starting_score = 100;
total_score = starting_score;
bet_asc = [0.05, 0.25, 0.5, 0.75, 0.95];
bet_des = [0.95, 0.75, 0.5, 0.25, 0.05];
num_items = 16;
reps = 9;
seq = 4;
seq_count = 0;
bankrupt = 0;
study_trial = 0;
range_items = fillArray([1,2,3,4], 18);
range_items = .concat.apply(, range_items);
shuffle(range_items);
star_pos = [[(- 0.7), 0.25], [(- 0.54), 0.25], [(- 0.39), 0.25], [(- 0.235), 0.25], [(- 0.08), 0.25], [0.08, 0.25], [0.235, 0.25], [0.39, 0.25], [0.54, 0.25], [0.7, 0.25]];
array_image = [‘Blue_6-4.png’, ‘Blue_7-3.png’,
‘Blue_8-2.png’, ‘Blue_9-1.png’,
‘Red_6-4.png’, ‘Red_7-3.png’,
‘Red_8-2.png’, ‘Red_9-1.png’,
‘Blue_6-4.png’, ‘Blue_7-3.png’,
‘Blue_8-2.png’, ‘Blue_9-1.png’,
‘Red_6-4.png’, ‘Red_7-3.png’,
‘Red_8-2.png’, ‘Red_9-1.png’
];

array_redprob = [0.4, 0.3, 0.2, 0.1, 0.6, 0.7, 0.8, 0.9,
0.4, 0.3, 0.2, 0.1, 0.6, 0.7, 0.8, 0.9];

array_correct = [0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1];
array_group = [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4];
array_desc = [0, 1];

function star_chos_red(temp){
switch(temp){
case ‘Red_9-1.png’:
return(range(9,0).sample());
case ‘Red_8-2.png’:
return(range(8,0).sample());
case ‘Red_7-3.png’:
return(range(7,0).sample());
case ‘Red_6-4.png’:
return(range(6,0).sample());
case ‘Blue_6-4.png’:
return(range(4,0).sample());
case ‘Blue_7-3.png’:
return(range(3,0).sample());
case ‘Blue_8-2.png’:
return(range(2,0).sample());
case ‘Blue_9-1.png’:
return(0);
}
}

function star_chos_blue(temp){
switch(temp){
case ‘Red_9-1.png’:
return(9);
case ‘Red_8-2.png’:
return(range(2,8).sample());
case ‘Red_7-3.png’:
return(range(3,7).sample());
case ‘Red_6-4.png’:
return(range(4,6).sample());
case ‘Blue_6-4.png’:
return(range(6,4).sample());
case ‘Blue_7-3.png’:
return(range(7,3).sample());
case ‘Blue_8-2.png’:
return(range(8,2).sample());
case ‘Blue_9-1.png’:
return(range(9,1).sample());
}
}

function group_swap_desc(temp) {
switch(temp) {
case 1:
return([0,4].sample());
case 3:
return([1,5].sample());
case 1:
return([2,6].sample());
case 1:
return([3,7].sample());
}
}

function group_swap_aes(temp) {
switch(temp) {
case 1:
return([8,12].sample());
case 3:
return([9,13].sample());
case 1:
return([10,14].sample());
case 1:
return([11,15].sample());
}
}

#Tutorial parameters
tutorial_range = [2, 6, 4, 1, 5, 0, 3, 7];
tutorial_rand_range = [0.5, 0.5, 0.5, 0.1, 0.5, 0.5, 0.5, 0.5];
tutorial_trial = 0;
total_score_tutorial = 100;
tutorial_range_bet = [7, 2, 1, 6, 4, 5, 4, 0, 3];
tutorial_bet_trial = 0;
tutorial_bet_rand = [0.5, 0.5, 0.2, 0.5, 0.5, 0.5, 0.8, 0.5, 0.5];

Here is a snippet of one of my audio components:
image
image

and I can’t post another image, but it isn’t disabled (the audio block)

Hey I was going through the doc you have in your reply, and added some things. I have some new errors now (similar to what happened before). Sorry for the wall of text! I will look more at the doc tomorrow.

What is line 2359 of CBT_js.js ?

tutorial_image = array_image[tutorial_range[tutorial_trial]];

How are array_image and tutorial_range defined ? One of them is undefined?

array_image = [‘Blue_6-4.png’, ‘Blue_7-3.png’,
‘Blue_8-2.png’, ‘Blue_9-1.png’,
‘Red_6-4.png’, ‘Red_7-3.png’,
‘Red_8-2.png’, ‘Red_9-1.png’,
‘Blue_6-4.png’, ‘Blue_7-3.png’,
‘Blue_8-2.png’, ‘Blue_9-1.png’,
‘Red_6-4.png’, ‘Red_7-3.png’,
‘Red_8-2.png’, ‘Red_9-1.png’
];
tutorial_range = [2, 6, 4, 1, 5, 0, 3, 7];

It seems like they aren’t being recognized although they are being declared. It is making me think there is some sort of error occurring in the beginning.

Are you declaring them in the Begin Experiment tab of a code component that appears before the component causing the error?

On second thoughts, did you declare them in an auto translate code tab? What you’ve written has semi colons like JS but single quotes like Python.

I declared that in the JS part, and in the Begin Experiment Tab. I recently changed it to single quotes, but it was originally double quotes and still the same issue.

I am really not understanding why the builder sound is not disconnecting correctly, there isn’t any custom code for it.

Also I made a new public git (seeing as all of these aren’t linking): https://gitlab.pavlovia.org/smmaul09/test7

I don’t think sound durations work. You need to either edit the sound to be the correct length or use tutorial_2_sound.stop() in a code component at the appropriate time. The duration should be blank.

Ah your a life saver! I replaced it with a custom .wav file and that did that trick (and removed duration). Now I am trying to fix this issue,

tutorial_image = array_image[tutorial_range[tutorial_trial]];

Your global code in begin_code is JS only which means you’re missing out on auto translate.

array_image = ['Blue_6-4.png', 'Blue_7-3.png',
               'Blue_8-2.png', 'Blue_9-1.png',
               'Red_6-4.png', 'Red_7-3.png',
               'Red_8-2.png', 'Red_9-1.png',
               'Blue_6-4.png', 'Blue_7-3.png',
               'Blue_8-2.png', 'Blue_9-1.png',
               'Red_6-4.png', 'Red_7-3.png',
               'Red_8-2.png', 'Red_9-1.png'
               ]

translates to:

array_image = ["Blue_6-4.png", "Blue_7-3.png", "Blue_8-2.png", "Blue_9-1.png", "Red_6-4.png", "Red_7-3.png", "Red_8-2.png", "Red_9-1.png", "Blue_6-4.png", "Blue_7-3.png", "Blue_8-2.png", "Blue_9-1.png", "Red_6-4.png", "Red_7-3.png", "Red_8-2.png", "Red_9-1.png"];

i.e. double quotes

I added the double quotes instead of the singles, it still seems like most of my variables aren’t being declared. When I inspect and try them in the console they don’t show the arrays or values I have declared. I am starting to think that I have something in my initial script that breaks my code or that there is an issue with the double sub setting.

I do appreciate your input, as I am really looking over everything!

I would start by putting everything into auto translate code components apart from the code_JS in the first routine as recommended in my crib sheet.

Perhaps you could test out your functions one by one

Array.prototype.sample = function(){
  return this[Math.floor(Math.random()*this.length)];
}

function fillArray(value, len) {
  var arr = [];
  for (var i = 0; i < len; i++) {
    arr.push(value);
  }
  return arr;
}

function range(size, startAt = 0) {
    return [...Array(size).keys()].map(i => i + startAt);
}

function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;

  // While there remain elements to shuffle...
  while (0 !== currentIndex) {

    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;

    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }

  return array;
}

None of the above are in my crib sheet (apart from a simpler shuffle) but I’d love to add them if they can be used to mimic Python functions and methods in JS.

Certainly, I pulled most of them from stack overflow. I’ll try to code in python and then pull everything over into the JS.

I think I am finding the issue, my variables are being declared locally and not globally? I am not sure why this is occuring.