Code insert for showing routine on condition not converting to Pavlovia

URL of experiment:

Description of the problem: Hello! I am trying to insert a routine for a break after N trials (in my case 30) - I saw a previous post (Using code to insert pauses within loops) and used the code suggested there, adapted for my number of trials. I inserted it in the beginning of the Break routine, and it works perfectly well on Builder, but when testing on Pavlovia the routine appears after every trial rather than after the 30th trial only. I checked Gitlab and both snippets of code show in the files.

This is the Python code:

if not trials.thisN in [30]: # on most trials:
    continueRoutine = False # don’t even start this routine
else:
    print(trials.thisN)

and this is the JS code that Builder translated (Auto->JS selected):

var _pj;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
if ((! _pj.in_es6(trials.thisN, [30]))) {
    continueRoutine = false;
} else {
    console.log(trials.thisN);
}

Thank you!

Try simplifying your Python to this:

if trials.thisN != 30: # on most trials:
    continueRoutine = False # don’t even start this routine

The auto-generated Javascript will be much simpler, and hence easier to find issues with. In your case, you don’t have a list of values, but just a single number (i.e. 30 instead of [30]), so you don’t need to use the Python function in. I guess that function doesn’t exist in Javascript, so a lot of that auto-generated code is finding a way to define an equivalent, which you don’t actually need.

Hello @Michael, thank you for the help, I copied the bit of code you suggested, into Each Frame rather than Begin Routine, and it works perfectly!