| Reference | Downloads | Github

Code Component for subject break malfunctioning in Pavlovia

Description of the problem:
I recently created a simple temporal discounting task experiment on PsychoPy in which I have 160 trials total (2 reps of 80 trials) and I want to give the participants a break after every 40 trials.

I inserted this code component into the “Begin Routine” section of the “break2” routine, and this works just fine when I run it locally on my computer in Psychopy:

Here’s a picture of the builder view component as well for reference:

However, in Pavlovia when I run the experiment it shows the break screen after EVERY trial instead of just the specified trials that I want it to. I am assuming this has something to do with the way that Pavlovia/JS keeps track of the trial number that is somehow different from the way it is done in Psychopy, but as I am a coding newbie I am not sure how to fix this issue.
If anyone has any tips or tricks that would be greatly appreciated, thank you so much!

Hi there,

change your code type to ‘both’ and move your code over to the ‘every frame’ tab instead :slight_smile:


Hi Becca,
Thanks so much for your reply! I tried both things, I moved the code to “every frame” and changed it to both and then hit the sync button again at the top of the builder view (I think that’s all I need to do to update it online, correct?) and while it works fine in PsychoPy it is still showing the break screen after every trial when I run it in Pavlovia.
If you have any other suggestions that would be greatly appreciated! Thanks again for your help :slight_smile:


I wonder - when I update the experiment locally do I need to export the HTML files again AND hit the sync button? Because when I look at my Gitlab page it says that the .psyexp files were updated recently but it looks like the html files and the .js files are still the original ones… maybe that might help?
Thanks again

Hi there,

thats odd this one should work for sure, please can you try clearing your browser cache to see if that pushes the update?


I am still having this exact problem. Was there any further feedback on this?

Hi There,

Looking back on this I suspect this is the use of .thisN - this code should actually now work if running in 2021.2 or later (because thisN now exists in PsychoJS) - alternatively use a trial counter to create breaks i.e.:

Add a code component, in the Begin Experiment tab write:

trialCounter = 0

and in the Begin routine tab type:

trialCounter += 1
if trialCounter % 10 >0:
    continueRoutine = False

This example would give a break every 10 trials.

Hope this helps!