Reference errors - variables not defined (although specified in beginning experiment code section)

Hello,

I’ve created a task using the Builder (PsychoPy v2020.1.2) which works fine when tested locally from PsychoPy, but gives me problems when I pilot it online with Pavlovia.

The errors I get are Reference Errors and they involve variables I create with a coding component at the beginning of the experiment.

E.g. ReferenceError: $instr_block1 is not defined
E.g. ReferenceError: $others_tr is not defined

These are variables with value of either 0 or 1 which I use in nReps$ to define whether certain loops should run or not depending on task conditions

Here below is my ‘begin experiment section’ where I define the variables, which will be then modified throughout the task

(initially I specified the variables simply as n = 0; etc… and not as var n = 0; so I tried like this but the problem is still there)

I also attach an example of loop where I use one of these variables:

I’ve seen many posts with reference errors here on the forum but I can’t figure out what my issue is exactly, since I do create these variables at the beginning of my experiment.
I am new to Python and JS (and online testing in general), so I tried to use the Builder components as much as possible and only include these small pieces of simple code.

Thank you, I really appreciate your help!

Try removing the $

Thank you very much, it worked.
Going on with the piloting I now encountered a different problem.

My task has a training part and a main experiment part which are very similar in structure. The training phase work ok, then I get the following error at the beginning of the main experiment loop (‘main_exp_loop’)

TypeError: Converting circular structure to JSON --> starting at object with constructor ‘PsychoJS’ | property ‘_logger’ -> object with constructor ‘Logger’ — property ‘_psychoJS’ closes the circle

Here I attempt to share my code since the task is still in piloting mode, I hope you can access it: https://gitlab.pavlovia.org/sxc1127/cued-task-switching/blob/master/html/sara_task_switch_beh_psychopy.js

Many thanks for your help again, I really appreciate!