psychopy.org | Reference | Downloads | Github

Problem ending a loop in JS (while working on PY)

URL of experiment:

Experiment in Pavlovia
Sourcecode

Description of the problem:

In our experiment, we have a loop that we want to terminate when the time controlled by a CountdownTimer is up.

This works perfectly in Python but it doesn’t work in JS (both localhost and Pavlovia). In JS we observe a continuous loop.

More details:

In this experiment we show a string of digits (e.g., 24312) and ask participants to type it as fast as possible as many time as possible within 10 seconds. After the time is up, the users have to rest for 10 seconds and then run a new trial with a new string of digits. There are in total 3 trials.

We have implemented it with an inner and outer loop, the inner is controlled by a timer (TIMER) and it is associated with a simple csv with just numbers (repetition 1,2,3…), while the outer loop is associated with a csv with the strings of digits for the task.

The main routine Task is initialized as follows:

//Task - Begin Experiment (JS)
TIMER = new util.CountdownTimer(TIME_LIMIT_SEC + 1);
RESET_TIME = true;

Every time the routine starts we check whether to reset the timer:

//Task - Begin Routine (JS)
if (RESET_TIME) {
    console.log('Resetting time')
    TIMER.reset(TIME_LIMIT_SEC+1);
    RESET_TIME = false;
}

In each frame of the routine, we check if the time is up:

//Task - Each Frame (JS)
if ((TIMER.getTime() <= 1)) {
    console.log('Time is up')
    continueRoutine = false;
    inner.finished = true; // <-- this doesn't seem to work
    RESET_TIME = true;
}

Debugging

We notice that the program never exists the inner loop.
It looks as if the instruction to terminate the loop when the time is up doesn’t work.
This is confirmed by the logging messages below:

innerLoopBegin
DEBUG unknown | import attributes from: {"repetition":1}
start Task
Resetting time
Time is up
DEBUG unknown | import attributes from: {"repetition":2}
start Task
Resetting time
Time is up
DEBUG unknown | import attributes from: {"repetition":3}
start Task

In JS all loops have to be addressed as trials, so trials.finished

Search the forum for a link to my crib sheet for more Pavlovia tips.

1 Like

Thanks so much @wakecarter!! :pray: :pray: :pray:
You saved my day! :partying_face: