Description of the problem: hello. I designed a dual task in builder mode and now trying to move it to the online platform via pavlovia. when I run the experiment, I end up with the error in the title “TypeError: Cannot read property ‘undefined’ of undefined” in the following line:
prac_selectedDigit = prac_cond[j];
where prac_selectedDigit, prac_cond, and j are all defined with “var” in above lines in the code.
prac_cond is defined as:
prac_cond = [5, 6, 7, 5, 6, 7];
the full part of the code where I encounter the error is as follows:
function practiceNumberTaskRoutineBegin(trials) {
return function () {
//------Prepare to start Routine 'practiceNumberTask'-------
t = 0;
practiceNumberTaskClock.reset(); // clock
frameN = -1;
routineTimer.add(1.800000);
// update component parameters for each repeat
// 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;
}
prac_selectedDigit = prac_cond[j]; //THIS IS THE ERROR LINE
prac_leftRightCond = prac_leftRightFull[j];
shuffle(prac_fullList);
if ((prac_selectedDigit === 5)) {
prac_fiveDigs = prac_fullList.slice(0, 5);
prac_unique = list((set(prac_fullList) ^ set(prac_fiveDigs)));
prac_toPrint = Number.parseInt("".join(map(str, prac_fiveDigs)));
shuffle(prac_fiveDigs);
shuffle(prac_unique);
if ((prac_leftRightCond === 0)) {
prac_digit1 = prac_unique[0];
prac_digit2 = prac_fiveDigs[0];
} else {
if ((prac_leftRightCond === 1)) {
prac_digit1 = prac_fiveDigs[0];
prac_digit2 = prac_unique[0];
}
}
} else {
if ((prac_selectedDigit === 6)) {
prac_sixDigs = prac_fullList.slice(0, 6);
prac_unique = list((set(prac_fullList) ^ set(prac_sixDigs)));
prac_toPrint = Number.parseInt("".join(map(str, prac_sixDigs)));
shuffle(prac_sixDigs);
shuffle(prac_unique);
if ((prac_leftRightCond === 0)) {
prac_digit1 = prac_unique[0];
prac_digit2 = prac_sixDigs[0];
} else {
if ((prac_leftRightCond === 1)) {
prac_digit1 = prac_sixDigs[0];
prac_digit2 = prac_unique[0];
}
}
} else {
if ((prac_selectedDigit === 7)) {
prac_sevenDigs = prac_fullList.slice(0, 7);
prac_unique = list((set(prac_fullList) ^ set(prac_sevenDigs)));
prac_toPrint = Number.parseInt("".join(map(str, prac_sevenDigs)));
shuffle(prac_sevenDigs);
shuffle(prac_unique);
if ((prac_leftRightCond === 0)) {
prac_digit1 = prac_unique[0];
prac_digit2 = prac_sevenDigs[0];
} else {
if ((prac_leftRightCond === 1)) {
prac_digit1 = prac_sevenDigs[0];
prac_digit2 = prac_unique[0];
}
}
}
}
}
j += 1;
prac_numberStim.setText(prac_toPrint);
// keep track of which components have finished
practiceNumberTaskComponents = [];
practiceNumberTaskComponents.push(prac_numberStim);
for (const thisComponent of practiceNumberTaskComponents)
if ('status' in thisComponent)
thisComponent.status = PsychoJS.Status.NOT_STARTED;
return Scheduler.Event.NEXT;
};
}
in Builder,this part is in the “begin routine” tab in the code component.
I cant see why I get the “undefined” error although I defined all the variables. Can anybody help me?
thanks in advance, tutku