# Pavlovia Sync Suddenly Deletes Core PsychoJS Variables

**URL:** <https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541>\
**Category:** Online experiments\
**Tags:** online, pavlovia\
**Created:** [April 9, 2025, 7:38pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541 "2025-04-09T19:38:38Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadavWeisler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nadavweisler/32/35196_2.png) [@nadavWeisler](https://discourse.psychopy.org/u/nadavWeisler)\
**Post date:** [April 9, 2025, 7:38pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/1 "2025-04-09T19:38:38Z")

</div>

Hi everyone,

I’ve been developing an experiment for a while, and suddenly I encountered a strange issue. When I sync my project with Pavlovia, it starts deleting the creation of core `PsychoJS` variables from the JS code.

Even if I manually add them back, the next sync removes them again.  
Here’s a screenshot comparing the commits to show what’s happening:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/7/a7ddf75f4df8051e3104c5fcb9771d013179547e.png)

Has anyone encountered this before? Any idea why this might be happening or how to prevent it?

Thanks in advance for your help!n.

---

<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:** [April 10, 2025, 12:38pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/2 "2025-04-10T12:38:52Z")

</div>

> [@nadavWeisler](#):
>
> it starts deleting the creation of core `PsychoJS` variables from the JS code.

What error do you get if you don’t edit the JS code?

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/17):
>
> The answer is (almost) never to edit the generated code When you create an experiment in Builder, PsychoPy then generates a Python file which you can use to run the experiment locally and two JavaScript files suitable for running the experiment online (using current and older browsers). If something doesn’t work, there may be a temptation to make edits directly to the Python/JavaScript files rather than the Builder file. However, this is generally a bad idea for two reasons: The process is o…

---

<div class="post-metadata">

**Author:** ![nadavWeisler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nadavweisler/32/35196_2.png) [@nadavWeisler](https://discourse.psychopy.org/u/nadavWeisler)\
**Post date:** [April 14, 2025, 12:40pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/3 "2025-04-14T12:40:14Z")

</div>

I got the error:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/6/e6391fe505ae5c8084dbc06923b8682337f57779.png)

---

<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:** [April 14, 2025, 2:12pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/4 "2025-04-14T14:12:44Z")

</div>

What version of PsychoPy are you using?

---

<div class="post-metadata">

**Author:** ![nadavWeisler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nadavweisler/32/35196_2.png) [@nadavWeisler](https://discourse.psychopy.org/u/nadavWeisler)\
**Post date:** [April 14, 2025, 2:33pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/5 "2025-04-14T14:33:11Z")

</div>

2024.2.4

---

<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:** [April 14, 2025, 2:47pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/6 "2025-04-14T14:47:12Z")

</div>

Thanks.

Is your “use version” in Experiment Settings blank? Do you have any loops? Do you have any code referring to currentLoop?

---

<div class="post-metadata">

**Author:** ![nadavWeisler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nadavweisler/32/35196_2.png) [@nadavWeisler](https://discourse.psychopy.org/u/nadavWeisler)\
**Post date:** [April 14, 2025, 2:50pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/7 "2025-04-14T14:50:10Z")

</div>

The use version is not blank, but contains 2024.2.0, I got multiple loops in the experiments but no code referring to currentLoop

---

<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:** [April 14, 2025, 2:53pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/8 "2025-04-14T14:53:53Z")

</div>

Try making it blank.

---

<div class="post-metadata">

**Author:** ![nadavWeisler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nadavweisler/32/35196_2.png) [@nadavWeisler](https://discourse.psychopy.org/u/nadavWeisler)\
**Post date:** [April 14, 2025, 2:56pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/9 "2025-04-14T14:56:43Z")

</div>

Done, nothing changed

---

<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:** [April 14, 2025, 2:59pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/10 "2025-04-14T14:59:18Z")

</div>

Did you check an incognito tab?

---

<div class="post-metadata">

**Author:** ![nadavWeisler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nadavweisler/32/35196_2.png) [@nadavWeisler](https://discourse.psychopy.org/u/nadavWeisler)\
**Post date:** [April 14, 2025, 3:00pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/11 "2025-04-14T15:00:09Z")

</div>

Yes

---

<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:** [April 14, 2025, 4:58pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/12 "2025-04-14T16:58:52Z")

</div>

Okay. Please could you add me (Wake) as a developer and I’ll take a look.

---

<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:** [April 14, 2025, 5:03pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/13 "2025-04-14T17:03:19Z")

</div>

However, first please set it to inactive and then piloting/running again.

---

<div class="post-metadata">

**Author:** ![nadavWeisler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nadavweisler/32/35196_2.png) [@nadavWeisler](https://discourse.psychopy.org/u/nadavWeisler)\
**Post date:** [April 14, 2025, 5:37pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/14 "2025-04-14T17:37:21Z")

</div>

> [@wakecarter](#):
>
> Wake

Hey I added you, 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:** [April 14, 2025, 8:23pm UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/15 "2025-04-14T20:23:57Z")

</div>

Hi.

I’ve taken a look and I’m pretty sure that the issue is that you are writing JavaScript code that isn’t compatible with PsychoJS. You have disabled your text components and replaced them with JS only code components. You implied that previous versions of the experiment worked fine. On what date did this experiment last run and what did you add next?

**Begin Routine**

```auto
let introDiv = document.getElementById("introTextDiv");
introDiv.innerHTML = introText;
introDiv.style.display = "block";

```

**End Routine**

```auto
// Hide intro text at end of trial
let introDiv = document.getElementById("introTextDiv");
if (introDiv) {
    introDiv.style.display = "none";
}

```

Here are some threads with the same issue:

> [@Variables not declared in auto JS generation](https://discourse.psychopy.org/t/variables-not-declared-in-auto-js-generation/43124):
>
> 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. async function updateInfo() { currentLoop = psychoJS.experiment; // right now there are no loops ..…

> [@frameDur is not defined error](https://discourse.psychopy.org/t/framedur-is-not-defined-error/11439):
>
> URL of experiment: [https://run.pavlovia.org/learningdevlab/3b\_complex\_binctl/html](https://run.pavlovia.org/learningdevlab/3b_complex_binctl/html) Description of the problem: When I click to pilot my experiment, I get through the dialog box, but then immediately get a frameDur error when I check the javascript console, my error is related to code that was generated automatically by psychopy/pavlovia [Screen Shot 2020-03-11 at 12.21.56 PM] // store frame rate of monitor if we can measure it successfully expInfo['frameRate'] = psychoJS.window.getActualFr…

and relevant tips

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/19):
>
> Builder isn’t Coder I strongly discourage the use of PsychoPy Coder for the creation of psychology experiments because Builder is easier to debug, share with others and translate into PsychoJS for use online. If you already have an experiment written in Coder, pasting the code into Builder code components is not sufficient to turn it into a Builder experiment. The logic of how to arrange an experiment is slightly different because of the way Builder works with components, routines and loops. F…

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/6):
>
> Use Auto → JS code components wherever possible Even if you aren’t planning to run your experiment online, using an Auto code component will help you spot syntax errors in your Python code. There are some cases where valid Python code comes up as a Syntax error on the JavaScript side but these are rare and, when you encounter then, you can switch to a Both code component and edit or delete the JavaScript side to highlight the fact that they contain code that won’t run online unedited. …

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/95):
>
> Own up to AI When trying to help people on the forum or through consultancy we are experiencing an increase in the amount of idiosyncratic or opaque code, coming from novice programmers who. ChatGPT and other AI tools can be a great help with programming tasks but they are not experienced with the architecture of PsychoPy Builder. If you use them, please add a comment to your code along the lines of # Created using ChatGPT to create random pseudo-words. Adding your main prompts as comments might…

---

<div class="post-metadata">

**Author:** ![nadavWeisler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nadavweisler/32/35196_2.png) [@nadavWeisler](https://discourse.psychopy.org/u/nadavWeisler)\
**Post date:** [April 15, 2025, 8:45am UTC](https://discourse.psychopy.org/t/pavlovia-sync-suddenly-deletes-core-psychojs-variables/44541/16 "2025-04-15T08:45:21Z")

</div>

Thanks! found the problem:

This row isn’t compatible with PsychoJS:

```auto
slider_value = document.querySelector('input[name="expectation"]:checked')?.value;

```

Instead, I changed it to:

```auto
let selectedInput = document.querySelector('input[name="expectation"]:checked');
let slider_value = selectedInput ? selectedInput.value : null;

```
