Reference Error: timer function not defined

I have an experiment that uses a clock to track the time in each trial. It works fine locally, but when I try to test it online, it gets stuck on the initializing screen. The developer tools tell me it is a reference error, and that the timer isn’t defined:

However, I have defined the timer in a code component:

I’ve tried a few different options for fixing it, to no avail:

  1. Change the name of myClock to timer
  2. try the Code type as “Both” or have it as “Auto → JS” (neither made a difference)
  3. moved code for myClock to a code component that is by itself in a single routine at the very start of the experiment, still in the “begin experiment” tab of the code component
  4. Used the crib sheet to ensure the JS code reads correctly

I imagine this is an easy fix, but I am not sure what else to try.

Put that code in Begin Experiment not Before Experiment

Yep, that solved it. Thanks wakecarter. Psychopy really knows how to humble me :woman_facepalming:

Just out of curiosity, is there a reason that having the clock code in Before Experiment works locally, but not online?