Ending loop after specified time not working on Pavlovia

Hi there, I’ve been trying to get a time limit working on pavlovia for quite awhile and have not been successful.

Psychopy 2020.2.2, windows10, firefox

I am attempting to start a timer on the first routine, and then terminate the loop after a specified number of seconds have passed by checking the timer. The set-up I have in builder works correctly, but not so much on pavlovia.

I tried various version of these attempts(
“mainSARTBlock” is my trial loop):

  1. A more “direct” translation of py to js (eg. using globalClock & maxTime) & just change the syntax to JS, but the code seemed to be completely ignored (i.e., no errors, but trials continued after specified time limit).

  2. The code below, but removing the “new util.Clock()” in Each Frame (and instead just check that timer. getTime() is >= 8 seconds). The code appears to be “ignored” as described above in #1.

  3. The code below, but swapping out “mainSARTblock” with
    a. “trials”
    b. “currentLoop” (both as per this
    For a, I get the error “ReferenceError: trials is not defined”
    For b, I get the same “code is ignored” behavior described in #1 above.

  4. The code below, but in eachFrame JS I swapped out “(((new util.Clock() - timer.getTime()) >= 8))” for both “((mainSARTBlock.thisTrialN === 2))”, “((currentLoop.thisTrialN === 2))”, “((currentLoop.thisRepN === 2))” & “((mainSARTBlock.thisRepN === 2))” to check if the issue is how trials end in JS for psychopy version 2020.2.2 , or if the issue is my time component. Same behavior of code being “ignored” (where I am looking for the loop to terminate after 2 trials to pass that are within the first iteration of the loop), which makes me think the issue is at least with the way I’m trying to force end a trial? Given this I thought it’d work. To no avail

  5. The code below, which has the same behavior of being “ignored” as described in #1 above.

I initially had errors where “timer” wasn’t being defined when I instead used .thisN instead of .thisTrialN, which I’m no longer getting, so I’m guessing the issue is in the EachFrame tab?

In Begin Routine:
Py:

if mainSARTBlock.thisN == 0: # only on the first trial
    startTime = globalClock.getTime()
maxTime = 8

JS:

if ((mainSARTBlock.thisTrialN === 0)) {
    timer = new util.Clock();
}
maxTime = 8;

In Each Frame:
Py:

if globalClock.getTime() - startTime >= maxTime:
    mainSARTBlock.finished = True
    continueRoutine = False

JS:

if (((new util.Clock() - timer.getTime()) >= 8)) {
    mainSARTBlock.finished = true;
    continueRoutine = false;
}

Any ideas on what to change to get this working in JS would be very very appreciated! About at my wit’s end with this one. Thanks!

1 Like