Learn to criterion loop

URL of experiment: Sign in · GitLab

Description of the problem: I want participants to do a task where they must achieve at least 75% correct to continue. If they dont, it loops back to the instructions and they do it again. The Python code works fine in PsychoPy, but the JS code I cant get to work on Pavlovia. Two issues:

First issue: is that when it gets to RestartPrac, it is correctly counting accuracy and displaying the “end_practice.setText” code. That is, if you get >= 3 correct it says “practice finished”, otherwise it reads the default text from the text display. However, it does not actually terminate the loop and go to the next routine (blank screen). <----EDIT: This issue was resolved: In the online version all loops have to be addressed as trials, irrespective of their real name, so practice_back.finished = 1 should be called trials.finished=1

Second issue: it doesnt seem to be resetting properly the nCorr variable when it loops back through “practice_back”. That is, say you get 4 correct, it says “practice finished”. If you go back through the “trials” routine and get 0 correct, it will still think you got 4 correct and will say “practice finished” (instead of saying the default text display". And it still doesnt end the loop (i.e., see first issue).

#####JS Code#######################

//PracBlockTrial: Begin Routine
nCorr = 1;

//**PracBlockTrial: End Routine
for (let eachResp=0; eachResp<psychoJS.experiment._trialsData.length; eachResp++)
{
nCorr += psychoJS.experiment._trialsData[eachResp][‘key_resp.corr’];
}

//**RestartPrac: Begin Routine
if ((nCorr >= 3)) {
practice_back.finished = 1;
skipThisTrial = true;
end_practice.setText(“practice finished, press ‘space’ to continue”);
}

############################

-The Python code was originally based off of the experiment called “DEMO redo practice” on Pavlovia, although it doesnt appear to work on there either. (Sorry, since I’m a new user I can only post two links).

-The PracBlock End Routine code was from the following discourse. I’ve tried quite a few variants and moving things around and still cant get it to work. Was hoping maybe someone else may have had better luck: Feedback after Block Rewritten in JavaScript for Online Studies

In the online version all loops have to be addressed as trials, irrespective of their real name, so this should be trials.finished=1;

2 Likes

Here is a solution, with a little different code than I had originally posted. If you dont get 75% correct (3 out of 4), it sends you back to the instructions screen (“InPrac”). Once you do, you go onto next section (“blank screen”).

#####JS Code#######################

// PracBlockTrial: Begin Routine
console.log(‘PractBlockTrial’);
if ((trials.thisN === 0)) {
number_correct = 0;
}

//PracBlockTrial: End Routine
if (key_resp.corr) {
number_correct = (number_correct + 1);
console.log('number_correct: ’ + number_correct);
}

//RestartPrac: Begin Routine
if ((number_correct >= 3)) {
console.log(practice_back);
trials.finished=1;
continueRoutine = false;
end_practice.setText(“Good job! You finished the practice. Press SPACEBAR to continue.”);
}

//RestartPrac: End Routine
number_correct = 0;

############################