I had an issue with an online experiment not getting past a routine (called “generate_code”) in an experiment. This routine was supposed to have a single text element (called “generating_text”) and last for two seconds. The problem lies in the PsychoJS.Status checking. Here’s the code that runs for each frame of the routine:
var frameRemains;
function generate_codeRoutineEachFrame() {
//------Loop for each frame of Routine 'generate_code'-------
let continueRoutine = true; // until we're told otherwise
// get current time
t = generate_codeClock.getTime();
frameN = frameN + 1;// number of completed frames (so 0 is the first frame)
// update/draw components on each frame
// *generating_text* updates
if (t >= 0.0 && generating_text.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
generating_text.tStart = t; // (not accounting for frame time here)
generating_text.frameNStart = frameN; // exact frame index
generating_text.setAutoDraw(true);
}
// the "2" on the line below below indicates this text should have a duration of 2 seconds
frameRemains = 0.0 + 2 - psychoJS.window.monitorFramePeriod * 0.75; // most of one frame period left
if (generating_text.status === PsychoJS.Status.STARTED && t >= frameRemains) {
generating_text.setAutoDraw(false);
}
// check if the Routine should terminate
if (!continueRoutine) { // a component has requested a forced-end of Routine
return Scheduler.Event.NEXT;
}
continueRoutine = false;// reverts to True if at least one component still running
for (const thisComponent of generate_codeComponents) {
if ('status' in thisComponent && thisComponent.status != PsychoJS.Status.FINISHED) {
continueRoutine = true;
break;
}
}
// check for quit (the Esc key)
if (psychoJS.experiment.experimentEnded || psychoJS.eventManager.getKeys({keyList:['escape']}).length > 0) {
psychoJS.quit('The [Escape] key was pressed. Goodbye!');
}
// refresh the screen if continuing
if (continueRoutine) {
return Scheduler.Event.FLIP_REPEAT;
}
else {
return Scheduler.Event.NEXT;
}
}
From logging, I found that when the text component was displayed for its 2 second duration, its status became “STOPPED”, although in the above code it is looking for the status to be “FINISHED” in the if conditional that reverts the continueRoutine to true. Assuming the component’s status is supposed to be updated to “STOPPED” when it’s done, the generated code should read:
if ('status' in thisComponent && thisComponent.status != PsychoJS.Status.STOPPED)
instead of:
if ('status' in thisComponent && thisComponent.status != PsychoJS.Status.FINISHED)