# Variables not declared in auto JS generation

**URL:** <https://discourse.psychopy.org/t/variables-not-declared-in-auto-js-generation/43124>\
**Category:** Online experiments\
**Created:** [December 2, 2024, 11:45am UTC](https://discourse.psychopy.org/t/variables-not-declared-in-auto-js-generation/43124 "2024-12-02T11:45:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Peney](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tom_peney/32/43492_2.png) [@Tom\_Peney](https://discourse.psychopy.org/u/Tom_Peney)\
**Post date:** [December 2, 2024, 11:45am UTC](https://discourse.psychopy.org/t/variables-not-declared-in-auto-js-generation/43124/1 "2024-12-02T11:45:35Z")

</div>

URL of experiment: [AudFlankTest\_legacy [PsychoPy]](https://run.pavlovia.org/PSkarratt/auditory_flanker_task/)

Description of the problem:  
Hello all! I seem to keep receiving ReferenceErrors when attempting to run this experiment online. The variables never seem to be declared in the auto-generated JS file, which I seem to recall has been the case previously. For example, in the below snippet, currentLoop is never defined anywhere using var/let/etc.

```auto
async function updateInfo() {
  currentLoop = psychoJS.experiment; // right now there are no loops
  ...
}

```

Any help would be appreciated, thanks!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 2, 2024, 11:59am UTC](https://discourse.psychopy.org/t/variables-not-declared-in-auto-js-generation/43124/2 "2024-12-02T11:59:16Z")

</div>

I see you are using quite an old version: 2022.2.4

Do you have any loops?

> [@No loop but this error "ReferenceError: currentLoop is not defined"](https://discourse.psychopy.org/t/no-loop-but-this-error-referenceerror-currentloop-is-not-defined/27684):
>
> URL of experiment: [fscratch [PsychoPy]](https://run.pavlovia.org/firestone/fscratch1/) Description of the problem: Hi everyone. I am trying to make a simple experiment here that just plays some audio with text on the screen. Then after the audio finishes, it goes to a “press space for the next segment” screen. I get the error listed in the title even though currently there is almost nothing in the file. I tried it with one that has 10 frames and got that error, decided to start from scratch because I couldn’t figure out why there was an er…

---

<div class="post-metadata">

**Author:** ![Tom\_Peney](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tom_peney/32/43492_2.png) [@Tom\_Peney](https://discourse.psychopy.org/u/Tom_Peney)\
**Post date:** [December 2, 2024, 1:43pm UTC](https://discourse.psychopy.org/t/variables-not-declared-in-auto-js-generation/43124/3 "2024-12-02T13:43:13Z")

</div>

Yeah the old version isn’t ideal, but sadly it’s what we have on the machines at the moment.

The experiment does have loops already - I did try wrapping the entire experiment in a loop but it didn’t seem to resolve the issue.

To clarify though, it’s not _specifically_ the `currentLoop` variable, that just happens to be the first occurrence. Quite a few variables don’t seem to have a decleartion.

For example, if I use a breakpoint and the console to define currentLoop, it will continue and then throw an error for frameDur. Again, if I manually define that in the console the same happens with the next variable etc.

```auto
async function updateInfo() {
  currentLoop = psychoJS.experiment; // right now there are no loops
  expInfo['date'] = util.MonotonicClock.getDateStr(); // add a simple timestamp
  expInfo['expName'] = expName;
  expInfo['psychopyVersion'] = '2022.2.4';
  expInfo['OS'] = window.navigator.platform;
  ...
  if (typeof expInfo['frameRate'] !== 'undefined')
    frameDur = 1.0 / Math.round(expInfo['frameRate']);
  else
    frameDur = 1.0 / 60.0; // couldn't get a reliable measure so guess
}

```

I could manually add declarations for all the variables to the JS file, but of course that isn’t ideal.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 2, 2024, 1:50pm UTC](https://discourse.psychopy.org/t/variables-not-declared-in-auto-js-generation/43124/4 "2024-12-02T13:50:08Z")

</div>

I think you have some form of compilation error. You shouldn’t need to define currentLoop and frameDur yourself.

> [@'ReferenceError: X is not defined' pop up one after another](https://discourse.psychopy.org/t/referenceerror-x-is-not-defined-pop-up-one-after-another/39740):
>
> URL of experiment: [Dembo [PsychoPy]](https://run.pavlovia.org/JellyfishS/dembo) Gitlab: [Sign in · GitLab](https://gitlab.pavlovia.org/JellyfishS/dembo) Built in v2023.2.0 I get ‘ReferenceError: currentLoop is not defined’ when I try to run the experiment. I tried to go to JS code and define currentLoop, but then I get ‘frameDur is not’ defined, and so on, and so on… I feel like there’s a deeper problem here I can’t see. What should I do to get my experiment running?

---

<div class="post-metadata">

**Author:** ![Tom\_Peney](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tom_peney/32/43492_2.png) [@Tom\_Peney](https://discourse.psychopy.org/u/Tom_Peney)\
**Post date:** [December 2, 2024, 3:48pm UTC](https://discourse.psychopy.org/t/variables-not-declared-in-auto-js-generation/43124/5 "2024-12-02T15:48:58Z")

</div>

It was indeed some custom code not being translated correctly and presumably causing a silent compilation error. Thanks for all your help!
