Outer loop terminates prematurely when setting inner loop to finished - continueRoutine issue?

URL of experiment: No repository · Evan MacLean / loop_test · GitLab

Description of the problem: I am experiencing a problem where I have nested loops and wish to terminate the inner loop (only) given certain responses in the outer loop. However, the outer loop (or its routines) seems to also be cancelled inadvertently.

The experiment runs correctly using the python code but I encounter an error when using PsychoJS. Specifically, when I abort the inner loop I use:

continueRoutine = false

…in the ‘each frame’ code component, in order to prevent the remainder of the routine in the aborted loop from being conducted. However, as a side effect, this seems to either (1) also exit the outer loop prematurely, or (2) cancel the routines in the outer loop as well. The experiment simply ends when it should not because there are additional iterations in the outer loop remaining. Importantly, if I do not attempt to end the inner loop early, the outer loop completes all iterations without a problem.

The linked experiment above is a minimal reproducible example of the phenomenon. I wonder if the continueRoutine = false code is also affecting other routines, perhaps due to global scope? Is there a way to specify a specific routine to be discontinued?

I’ve been struggling with this for days and am very grateful for any insights!

Yes, setting continueRoutine=false on every frame will cause that routine never to run at all for any loop.

If you want to end a loop you need:

nameOfMyLoop.finished=true

Hi @jon, many thanks for your reply. To clarify:

I do use:

nameOfMyLoop.finished=true

to kill the loop.

I then also use:

continueRoutine=false

in the ‘each frame’ code component for the routine within the (inner) loop being ended. This is done within an if statement so that continueRoutine is only set to false if the conditional statement that should end the loop is true. Here is the code for the each frame component of the inner loop routine:

if (skip_step_two) {
step2_loop.finished = true;
continueRoutine = false;
}

I do this because in another thread @dvbridges suggests that while stopping the loop works fine with PsychoJS, this will not end the remaining components of the routine within the loop unless continueRoutine is set to false each frame.

The unexpected consequence in my code is that the outer loop and / or its routines also seem to be aborted when setting the inner loop to finished. In other words, when setting the inner loop to finished, and the inner loop routine to continueRoutine = false, this seems to affect the outer loop and its routines. So, I am wondering if the continueRoutine = false code is also unintentionally affecting other routines in the outer loop (outside of the specific routine were continueRoutine was set to false).

Thanks so much if you or @dvbridges have additional thoughts!

continueRoutine = false; has no direct effect on the loops, inner or outer. What might be happening is tha teh value of skip_step_two is never returned to be false. If it’s always true then this routine ends itself every time it starts and therefore looks like the loop ended (it just ran really fast with no visible routines in it?)

Thanks again for your reply @jon. It’s good to know that continueRoutine = false; has no impact on the loops. My issue is not that inner loop or associated routines fail to execute but rather that the outer loop seems to end prematurely. Here is the overall flow:

If skip_step_two = false, then step 1 completes, followed by the step_2_loop before returning to the next iteration of the trials_loop (which is the outer loop). This is expected and runs correctly.

What is unexpected – and only occurs with PsychoJS (but not PsychoPy)– is that if skip_step_two = true, not only does step_2 not execute (which is expected) but the remaining iterations of the trials_loop, which contain step 1 also fail to execute (or the step1 routine is also suppressed, making it seem as if trials_loop has ended.

So, as soon as I implement skip_step_two = true, the entire experiment concludes when instead it should return to the next iteration of the trials_loop.

Do you have thoughts on what might cause this behavior? Thanks again for your helpfulness!

For any others reading this thread, it looks like the issue may be a bug which is being addressed here.

Hi everyone,
I have the same issue as @sisunator with nested loops: when I finish the inner loop, the outer loop gets closed too in PsychoJS. It worked fine in PsychoPy.
Does anyone know whether this will be fixed anytime soon ?
Thanks!

I think this has been addressed. What version are you using? (maybe provide link to your study?)

Dear all @jon, dear @dvbridges ,

This is my first interaction with the forum. I have been reading this thread with interest, as well as the other thread “sisunator” was mentioning in the previous comment.

It looks like I have the same issue as “fannyj” and “sisunator” with nested loops.
URL of my task: Sign in · GitLab
Image of the flow below

The task consists in 150 sequences, controlled by the loop DSP_sequences (read in random order)
Each sequence is made by 10 display, controlled by the loop (read in sequential order)
The inner loop trials has nReps set to 1000. If the answer to the routine DSP_display is NOT correct, an Error_Feedback is displayed and the trial is repeated again.
If the answer to the routine DSP_display is CORRECT, the trial is not repeated and, according to the DSP_sequence loop, the next display of the sequence is shown. To control this, I have accounted for a custom code after the keyboard response in the routine DSP_display:
if (key_resp_2.corr == 1) {

trials.finished = 1;

}

However, as the other users mentioned, this is working just fine in Psychopy, while not on Pavlovia. If the condition above is true, then the code exit the trials loop (which is correct), but also exit the 2 other outer loops, ending prematurely the task.

I hope to have well explained the issue, and looking forward to know if this issue occurred because I have done something wrong, or because it might be a bug that still needs to be addressed.

Many thanks for you help!

Hi @fannyj, did you find any solution to overcome this issue? many thanks !

Hi @jon,
A bug report has been created but not adressed yet, see https://github.com/psychopy/psychojs/issues/68
So it crashes on Pavlovia only, exactly as @pruggeri describes.

To answer your question @pruggeri (thanks for tagging me, I didn’t realize my question had answers yet), no I haven’t been able to solve this issue and we are currently starting the study with local computers (PsychoPy only).

Thanks for your answer @fannyj! I think we will start with local computers as well, or in the meantime try another way to write the task to avoid the inner loop…
We keep in touch and look forward to have this working on Pavlovia!

Hi @pruggeri, going to try and get this sorted for the next release - you should be able to keep track of this on the issues list link above.

Ok, this is fixed already in the latest (pre-release version) PsychoPy. The actual release of version 2020 will be out soon with all fixes built in, so if you can wait a short period of time this should work.

That’s great! many thanks about that!