Reference error "$ not defined" on Pavlovia

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.

2 Likes

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)

Hello,

Thank you very much for your reply! Here is the url of the experiment: 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.

@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.

@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?

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

1 Like

@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?

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.

1 Like

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.

1 Like

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?

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

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.

determiner = -1
determiner2 = -1

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

image001.jpg

Hi David,

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

Thanks

Hardeep

image001.png

image001.jpg

2 Likes