| Reference | Downloads | Github

Loop.finished=true works offline but doesn't work online

Description of the problem:
PsychoPy version: 2020.1.3
Os: Win10

Hi everyone, I want to display 64 stimuli among a pool of 851 stimuli, so I need the Loop (the name of Loop I set is obsertrials) to end when the number of trials reached 64. I used a code component in the loop and write the code in the End Routine Tab as follows:

It can work perfectly offline in my computer, but when I upload it on Pavlovia, it doesn’t work any more. The Loop will continue until all the 851 rows/stimuli are selected.

I also try to use the solution mentioned in Loop.finished=true No longer working , take “end the loop on the 2nd repetition of that current loop” as an example, it suggested that use code as:

if (currentLoop.thisRepN == 2)
trials.finished = true; // to end any loop, use ‘trials’

I tried to use this code, but the Builder set a error like:
NameError: name ‘trials’ is not defined

Since there are three loops in my Flow, like as follows:

I changed the name of first loop from “obsertrials” to “trials”, and the code “if trials.this N==63 trials.finished=true” can work both offline and online (interesting). But there are still two loops left, and I want them end after certain number of stimuli displaying just like the first one. But it is impossible for me to change all three names of loops to “trials” at the same time, because they should differ from each other.

Is there any suggestions?
Thanks very much in advance for any help.


I have a very similar problem.

The following code works perfectly offline but my loop will not terminate online when my learning criteria has been met, despite the python code being reworked 3 different ways and using each of them on py>autojs

Maybe this is a pavlovia issue that needs a bit of attention and not anything we are doing wrong?



I have a similar problem. In one of my loops, the second routine is conditional on the first so I added a code component to the second routine that makes it stop if the answer to the first routine was “n” (no). I’ve set the code type to “both” (i.e., Py and JS) in order to make it work online. Still, while it works perfectly fine offline, it does not online, i.e., it just ignores the code and always continues with the second routine independent of the answer given to the first one. There’s no error message either.

I don’t know if there is something wrong with the translation of the code or if the problem lies somewhere else?

Here’s my code: Pavlovia

Any help on this would be much appreciated!


Hi @Zoey2020,
Happy to look into this further, but

is making me think that when you tried this you just misspelled trials (in your quoted comment it said “trails” is not defined.
If this is the exact error message you got I would try the trials.finished solution again, making sure to double check any spelling, and keeping the loop names as you previously had them.

A similar discussion is happening here: Conditional Loop not working in Pavlovia

suggesting this might be a common problem that needs addressing.

Another discussion here with the solution given. Has almost identical title so really should have been obvious during posting. :frowning:

1 Like

Hi @Bobby_Thomas,

Thanks very much for your reply and carefulness. The misspelled “trails” is my mistake when I write it.
I noticed that you solved a similar problem by using PychoPy version 3.2, so I tried to use the version 3.2.4 now, and set the code as follows:
But the error still exist when it runs on computer, like:

Thanks again!

(1) reverting to 3.2.4 doesn’t work
(2) my code was already in the trials.finished=true format when using 2020.1

@Zoey2020 The solution to the problem is to EITHER revert to an older version that was working for you with the actual name of the loops (which I don’t think is the case), OR to use the most up to date PsychoPy with the trials.finished=true format. If you use trials.finished=true before PsychoPy 2020 and you don’t have a specific loop called trials then it will not work.

1 Like

Hi! Nice to see you here! :slight_smile: