| Reference | Downloads | Github

"Take a break" works locally but not online

Oh believe me the developers know all about it, and to be honest they’ve already done an incredible job. Automatically translating code from Python to JS at all is a tremendous achievement given how different the two languages are. Everything else in the builder is just a representation that can be compiled into any language that they’ve programmed those objects into, so it’s not trying to directly translate python into javascript, but code elements are pure python code, so translating them procedurally without making you write out python code and javascript code separately and manually? Sure, doing it better would be nice, but from the perspective of someone who has manually coded whole experiments from scratch in both languages, doing it at all is very impressive.

Also I think I know how to fix it. Try moving the code to “every frame” instead of “begin routine”. I’ve seen other people say that skipping trials only works if the skip code is in the “every frame” tab.


Putting the code to every frame works like a charm! Thank you so much for your help. I do appreciate the auto Python to JS functionality, as well as PsychoPy overall. The learning curve is much smoother compared with MATLAB/Psychtoolbox. The community support, like this one, is incredible. Thank you.

Hi Jonathan, I think i’m having a trial-skipping issue that’s related to some of this discussion but I can’t quite get my loop to operate correctly and you seem to have some experience here.

The loop is not behaving as it is supposed to online (works fine locally).

I used your every frame suggestion for some of my code and it made it run better, but still not quite as desired.

I’ll try and explain:

To loop is supposed to work like this:
(1) object is correct if within 150 pixels (i.e., inside the polygon i’ve included for easy testing)
(2) if an object is answered correctly twice in a row , (i.e., on two consecutive occasions that item, e.g., cow is attempted) it drops from the loop (i.e., its value goes from 0>1>2; if it is answered incorrectly, its value in the dict drops to 0 - the values for the other objects should stay the same here and they should still be skipped if their value reaches 2)
(3) loop terminates when all objects placed in correct location twice in a row (i.e., all objects values are 2 in dict).

The java script is behaving in the following undesirable way:
(1) if all trials are answered correctly it terminates exactly when it is supposed to
(2) if an object is answered incorrectly the dict for that object seems to reset to 0 as it is supposed to
(3) it will then finish all the objects in the that round of the loop
(4) it will then demand two new full loops in which I answer the original incorrect trial correctly (i.e., it is not skipping)
(5) then it will start a final round of the loop and terminate only once it reaches the object I originally answered incorrectly (even though that object reached its desired value of 2 a number of trials ago)

note* currently I have all values of objects in dict set to 1 for quicker testing.
note* works fine in psychopy builder

do you know whats going wrong? All of that seems complicated but I think its just something to do with skipThisTrial :thinking:

Any help you have will be very much appreciated!


That’s an interesting and complex failure. I don’t have a definite answer for you, I’m afraid, but my guess is that it might have to do with the dictionary, or the way it is updated between loops. That said, I have to say that at a glance I don’t see an obvious problem with any of the code around obs_dict. It looks like it should do exactly what you intend it to.

I recommend, for debugging purposes, adding some console.log calls whenever obs_dict is updated, so you can double-check that it’s being updated correctly. That may help you isolate the issue.

okay to update - i’ve tried a million examples of changing components to each frame/end routine etc and had no luck.

where do i put these console.log commands? online in the javascript code?


I am having this same issue where my break works perfectly in psychopy, but does not in Pavlovia. There is no error message, it simply skips the break. Basically, I want a 30 second break after half of the trials have been completed (304). Attached is the code I currently have that works in psychopy.

It worked for me online when I change the loop name to “trial”. In your case, do not use “Flankers_Test” as the loop name. Use “trial” instead. So the if command will be “if trial.thisN !=303:”

If you need to use Flankers_Test as the loop name, then you will need a separate variable that counts the number of trials. E.g., a TrialCounter that is initially 0, and then increases value by 1 after each trial. After that, you can do “if TrialCounter = 303:” or something like that.

I tried changing it to trial, and PsychoPy quits the experiment. I am fairly new to PsychoPy, how would a trial counter look?

i got the same error as you and when i changed the name of the loop to “trials” it is finally working…
maybe the problem is that you changed it to “trial” but it should be “trials” (I tried it whit “trial” but it was not working online - it looks like it should be named really “trials” with S at the end)

trials.thisN works online in 2020.1 but for 2021.1 you have to change the loop name to snapshot on the JS side only, i.e. snapshot.thisN


You killed the game :star_struck:

I just lost the game…

trials.getTrialIndex() should also work online