Skip to content

Commit

Permalink
BF: beginRoutineJS code was broekn if continueRoutine==False
Browse files Browse the repository at this point in the history
The output tried to return early (as if in the eachFrame block) whereas
what it should have done was store continueRoutine as a global.

Key changes
--------------

1. Set continueRoutine as a global at *top* of beginRoutine code block
so it can be modified later in that block

2. remove this line from eachFrame (it would undo above fix)
	let continueRoutine = true; // until we're told otherwise

3. remove the erroneous code where the return Scheduler.Event.NEXT was
made dependent on continueRoutine
  • Loading branch information
peircej committed Dec 4, 2020
1 parent 817ed9e commit ae20cb1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
13 changes: 5 additions & 8 deletions psychopy/experiment/routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ def writeRoutineBeginCodeJS(self, buff, modular):
code = ("//------Prepare to start Routine '%(name)s'-------\n"
"t = 0;\n"
"%(name)sClock.reset(); // clock\n"
"frameN = -1;\n" % self.params)
"frameN = -1;\n"
"continueRoutine = true; // until we're told otherwise\n"
% self.params)
buff.writeIndentedLines(code)
# can we use non-slip timing?
maxTime, useNonSlip = self.getMaxTime()
Expand Down Expand Up @@ -304,15 +306,11 @@ def writeRoutineBeginCodeJS(self, buff, modular):
buff.writeIndentedLines(code)

# are we done yet?
code = ("// check if the Routine should terminate\n"
"if (!continueRoutine) {"
" // a component has requested a forced-end of Routine\n"
" return Scheduler.Event.NEXT;\n"
"}\n")
code = ("return Scheduler.Event.NEXT;\n")
buff.writeIndentedLines(code)

buff.setIndentLevel(-1, relative=True)
buff.writeIndentedLines("};\n")
buff.writeIndentedLines("}\n")
buff.setIndentLevel(-1, relative=True)
buff.writeIndentedLines("}\n")

Expand All @@ -329,7 +327,6 @@ def writeEachFrameCodeJS(self, buff, modular):
buff.setIndentLevel(1, relative=True)

code = ("//------Loop for each frame of Routine '%(name)s'-------\n"
"let continueRoutine = true; // until we're told otherwise\n"
"// get current time\n"
"t = %(name)sClock.getTime();\n"
"frameN = frameN + 1;"
Expand Down
3 changes: 2 additions & 1 deletion psychopy/tests/data/correctScript/js/correctTextComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function trialRoutineBegin() {
trialClock.reset(); // clock
frameN = -1;
routineTimer.add(1.000000);

// update component parameters for each repeat
// keep track of which components have finished
trialComponents = [];
Expand All @@ -118,7 +119,7 @@ var frameRemains;
var continueRoutine;
function trialRoutineEachFrame() {
//------Loop for each frame of Routine 'trial'-------
let continueRoutine = true; // until we're told otherwise

// get current time
t = trialClock.getTime();
frameN = frameN + 1;// number of completed frames (so 0 is the first frame)
Expand Down

0 comments on commit ae20cb1

Please sign in to comment.