# Reference error "$ not defined" on Pavlovia

**URL:** https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359
**Category:** Online experiments
**Tags:** pavlovia
**Created:** [April 14, 2020, 4:12pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359 "2020-04-14T16:12:28Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![BaharSener](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/baharsener/32/6703_2.png) [@BaharSener](https://discourse.psychopy.org/u/BaharSener)
#### Post date: [April 14, 2020, 4:12pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/1 "2020-04-14T16:12:28Z")

</div>

I have a memory task I built on the latest version of PsychoPy. I want to move the task online through Pavlovia. The task runs fine on the laptop, but when I try to pilot it on Pavlovia, I enter the participant number and immediately get “Reference error: $numEncoding not defined” and the task won’t run.  
I use numEncoding so that encoding phase runs for 25 trials. In the ‘begin experiment’ component, I have the variable set as numEncoding = 25.

I tried to troubleshoot this by changing “code type” from “py” to “both”. Now when I reopen the task and look at the code component, it says “Auto --\> JS” instead of “both” and even if I set it to both, this does not seem to save. I’m not sure if this is the problem, and I’d appreciate any help or insight on this. This is my first time working with Pavlovia!

I can also share the url of the experiment if you think it would be helpful.

---

<div class="post-metadata">

### Author: ![amazar](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@amazar](https://discourse.psychopy.org/u/amazar)
#### Post date: [April 14, 2020, 7:55pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/2 "2020-04-14T19:55:06Z")

</div>

Yes, if you could share the code that you’re using it would be very helpful.

Psychopy code components default to “Auto -\> JS” but this doesn’t affect the underlying code as long as you don’t type anything in the python side of the code component (if you do it might change any custom javascript code that you’ve written)

---

<div class="post-metadata">

### Author: ![BaharSener](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/baharsener/32/6703_2.png) [@BaharSener](https://discourse.psychopy.org/u/BaharSener)
#### Post date: [April 14, 2020, 10:32pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/3 "2020-04-14T22:32:09Z")

</div>

Hello,

Thank you very much for your reply! Here is the url of the experiment: [https://run.pavlovia.org/lcdlab/spatialmemory](https://run.pavlovia.org/lcdlab/spatialmemory)

I didn’t type anything extra, I just had the code type set to “py” as it was default, later on went back and changed to “both” after I read here that it could cause issues/may be why the experiment isn’t running. At the time “Auto -\> JS” didn’t even show up, when I opened it later it was set to it.

---

<div class="post-metadata">

### Author: ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)
#### Post date: [April 14, 2020, 11:35pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/4 "2020-04-14T23:35:47Z")

</div>

@BaharSener, I believe this issue relates to the use of dollar signs to indicate code use in your loops, specifically the use of `$numEncoding` . The `$` is causing the reference error, so if you remove this, recompile and sync with Pavlovia (and maybe refresh the browser cache), the task should move on from that error.

---

<div class="post-metadata">

### Author: ![BaharSener](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/baharsener/32/6703_2.png) [@BaharSener](https://discourse.psychopy.org/u/BaharSener)
#### Post date: [April 15, 2020, 12:29am UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/6 "2020-04-15T00:29:25Z")

</div>

@dvbridges thank you very much! I didn’t explicitly use the symbol $ in my code, so I am not sure how to remove it. Would I be modifying the html file?

---

<div class="post-metadata">

### Author: ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)
#### Post date: [April 15, 2020, 12:30pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/7 "2020-04-15T12:30:35Z")

</div>

@BaharSener, it looks like it was used in the loop called `EncodingTrials` - see the `nReps` field.

---

<div class="post-metadata">

### Author: ![BaharSener](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/baharsener/32/6703_2.png) [@BaharSener](https://discourse.psychopy.org/u/BaharSener)
#### Post date: [April 15, 2020, 5:10pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/8 "2020-04-15T17:10:16Z")

</div>

@dvbridges got it! You are right, I used $ symbol in the loops, just didn’t realize it.

I removed the from the loop code and synced the project (which created a new experiment, url: https://run.pavlovia.org/lcdlab/spatial-memory/html ). Now I get the same error message without the symbol, “Reference error: numEncoding not defined”. Any ideas what may be causing this?

---

<div class="post-metadata">

### Author: ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)
#### Post date: [April 15, 2020, 5:15pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/9 "2020-04-15T17:15:37Z")

</div>

Yes, I think the problem is that the code in the code component in the `initCode` routine has not been translated over to JS. If you open the code component, and the right panel is blank, select the code type as “auto-\>js” again, and it should refresh and write the JS code in the right panel.

---

<div class="post-metadata">

### Author: ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)
#### Post date: [April 15, 2020, 5:22pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/10 "2020-04-15T17:22:29Z")

</div>

Btw, you will want to remove the Python specific import statements and related code from the code component (e.g., accessing files from a path on your local computer), because they will not work online.

---

<div class="post-metadata">

### Author: ![BaharSener](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/baharsener/32/6703_2.png) [@BaharSener](https://discourse.psychopy.org/u/BaharSener)
#### Post date: [April 15, 2020, 5:59pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/11 "2020-04-15T17:59:28Z")

</div>

Thank you for all your input @dvbridges this is all very helpful! Sorry if this is an obvious question but- would I change those local file paths to url of the pavlovia files?

---

<div class="post-metadata">

### Author: ![hk-adams](https://avatars.discourse-cdn.com/v4/letter/h/c68b51/32.png) [@hk-adams](https://discourse.psychopy.org/u/hk-adams)
#### Post date: [December 18, 2020, 2:31pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/12 "2020-12-18T14:31:40Z")

</div>

Hi, I am also experiencing this error, I have updated all code components to Auto JS and still receive the ReferenceError for determiner2

The experiment is [https://run.pavlovia.org/hk-adams/simon-only-eg](https://run.pavlovia.org/hk-adams/simon-only-eg)

---

<div class="post-metadata">

### Author: ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)
#### Post date: [December 18, 2020, 4:15pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/13 "2020-12-18T16:15:02Z")

</div>

Hi @hk-adams, looks like determiner and determiner2 were not declared by PsychoPy when generating the JS code. I have not looked into why, but the code seems to appear in the “Before Experiment” code component tab? Try moving the Python code below to Begin Experiment, and then the auto-js compiler should declare the vars properly.

```auto
determiner = -1
determiner2 = -1

```

---

<div class="post-metadata">

### Author: ![hk-adams](https://avatars.discourse-cdn.com/v4/letter/h/c68b51/32.png) [@hk-adams](https://discourse.psychopy.org/u/hk-adams)
#### Post date: [January 12, 2021, 3:19pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/14 "2021-01-12T15:19:43Z")

</div>

Hi David,

Thanks for the advice, I have added the code to Begin Experiment, but now I get the error below! Any help is much appreciated.

Thanks

Hardeep

![image001.png](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/9/59edce2bab30f62e3550782acfa8f6fad79af0b0.png)

![image001.jpg](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/8/08510993fd2ac1be3306b30d31248c050332925a.jpeg)

---

<div class="post-metadata">

### Author: ![hk-adams](https://avatars.discourse-cdn.com/v4/letter/h/c68b51/32.png) [@hk-adams](https://discourse.psychopy.org/u/hk-adams)
#### Post date: [January 14, 2021, 12:06pm UTC](https://discourse.psychopy.org/t/reference-error-not-defined-on-pavlovia/12359/15 "2021-01-14T12:06:36Z")

</div>

Hi David,

Don’t worry about the message below, I have changed the experiment and its running ok.

Thanks

Hardeep

![image001.png](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/9/59edce2bab30f62e3550782acfa8f6fad79af0b0.png)

![image001.jpg](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/8/08510993fd2ac1be3306b30d31248c050332925a.jpeg)
