# Nameerror when using Javascript on builder

**URL:** <https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592>\
**Category:** Builder\
**Created:** [October 27, 2019, 2:52am UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592 "2019-10-27T02:52:11Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![CatK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/catk/32/6087_2.png) [@CatK](https://discourse.psychopy.org/u/CatK)\
**Post date:** [October 27, 2019, 2:52am UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/1 "2019-10-27T02:52:11Z")

</div>

If this template helps then use it. If not then just delete and start from scratch.

**OS** (e.g. Win10):  
**PsychoPy version** (e.g. 3.2.4.x):  
**Standard Standalone? (y/n)** If not then what?:  
**What are you trying to achieve?:**  
familiarizing myself with psychopy builder and online experiment coding  
**What did you try to make it work?:**  
My experiment is super simple right now. I have a “var num\_learn = 12” variable declared in Begin Experiment. For my first learn trials experiment, I refer to num\_learn using $num\_learn. But when I run it, I keep getting the “NameError: name ‘num\_learn’ is not defined” message.

I used Python previously and there was no problem. I wrote the same code in JS before I pushed it online. I got the same “ReferenceError” when I tried to run it online. So I went back to the builder and removed the Python code (when I had both codes, there was no problem) and worked on the JS code. But I keep running into this problem and now I have no idea what’s happening.

Thanks!  
**What specifically went wrong when you tried that?:**  
Include pasted full error message if possible. “That didn’t work” is not enough information.

---

<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:** [October 27, 2019, 6:36pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/2 "2019-10-27T18:36:28Z")

</div>

hi @CatK, try removing the “var” declaration. PsychoPy finds all your variables used in the experiment and declares them globally using `var`, but if you do this yourself you restrict scope to that part of the experiment (e.g., beginning of the experiment)

---

<div class="post-metadata">

**Author:** ![CatK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/catk/32/6087_2.png) [@CatK](https://discourse.psychopy.org/u/CatK)\
**Post date:** [October 27, 2019, 6:53pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/3 "2019-10-27T18:53:10Z")

</div>

I removed the “var” declaration" but still got the same nameerror. Here are some screenshots of my codes and settings. Is there anything else that I can try/change?

 ![Screenshot%20(66)%20-%20Copy](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/e/1e892a988b8b4430f1bcc2089e29bc25f0deb62e.jpeg) ![Screenshot%20(67)%20-%20Copy](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/9/89e9e216ce708f67f726031df906625d84905a4c.jpeg) ![Screenshot%20(68)%20-%20Copy](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/5/955e538014cfa3b11f890881544c20cff69119fd.png) ![Screenshot%20(69)](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/e/ae797f055fa31a42c1e050dc4572c6a323ef2422.jpeg) ![Screenshot%20(64)](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/c/3c28d858f4b8cc86fc82b1b318c96ead74b7f0c5.png) ![Screenshot%20(65)%20-%20Copy](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/d/9de0b8bd8ee53b0c9df5fb96f223a2d474e90e90.jpeg)

---

<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:** [October 27, 2019, 8:16pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/4 "2019-10-27T20:16:35Z")

</div>

Thanks, would you mind sharing the URL for the task?

---

<div class="post-metadata">

**Author:** ![CatK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/catk/32/6087_2.png) [@CatK](https://discourse.psychopy.org/u/CatK)\
**Post date:** [October 27, 2019, 8:56pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/5 "2019-10-27T20:56:40Z")

</div>

I deleted the original depository. I tried to commit it again but it doesn’t show on my pavolovia page.

Is there any demo project you recommend that involves using js code snippet? Thanks!

---

<div class="post-metadata">

**Author:** ![CatK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/catk/32/6087_2.png) [@CatK](https://discourse.psychopy.org/u/CatK)\
**Post date:** [October 27, 2019, 9:41pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/6 "2019-10-27T21:41:25Z")

</div>

I had some problem pushing it online (i deleted the original online repository).The attachment is the psyexp file. Thank you so much!

[experiment\_testing 1.psyexp](https://discourse.psychopy.org/uploads/short-url/3oEaQElGnzzI0HYF4fQVWN8AN88.psyexp) (16.1 KB)

---

<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:** [October 28, 2019, 11:40am UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/7 "2019-10-28T11:40:10Z")

</div>

Ok, well I uploaded this task ok, but got a ReferenceError because `item_blast` does not exist. Is there a conditions file I should have? Or should there be another array called `item_blast`?

---

<div class="post-metadata">

**Author:** ![CatK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/catk/32/6087_2.png) [@CatK](https://discourse.psychopy.org/u/CatK)\
**Post date:** [October 28, 2019, 2:27pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/8 "2019-10-28T14:27:35Z")

</div>

Sorry for that. I changed the variable name a bit and clearly didn’t change all of them. Here’s the updated one. I’m so sorry for the inconvenience.[experiment\_testing 1.psyexp](https://discourse.psychopy.org/uploads/short-url/mE8fK25Qo59fOcRk3VLFnWg6FMg.psyexp) (16.1 KB)

---

<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:** [October 28, 2019, 2:42pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/9 "2019-10-28T14:42:53Z")

</div>

Thanks, this also compiles correctly, and the task runs just fine. Can you please try refreshing your browser cache to make sure that you are running the most up to date script? On Windows, you would open your task in your browser from Pavlovia and press “Shift + F5”.

---

<div class="post-metadata">

**Author:** ![CatK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/catk/32/6087_2.png) [@CatK](https://discourse.psychopy.org/u/CatK)\
**Post date:** [October 28, 2019, 3:50pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/10 "2019-10-28T15:50:26Z")

</div>

Which version of psychopy do you use?

Somehow I’m not able to open psychopy app on my computer now, which is very weird.

---

<div class="post-metadata">

**Author:** ![CatK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/catk/32/6087_2.png) [@CatK](https://discourse.psychopy.org/u/CatK)\
**Post date:** [October 28, 2019, 4:52pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/11 "2019-10-28T16:52:56Z")

</div>

Which version of psychopy do you use?

Somehow I’m not able to open psychopy app on my computer now, which is very weird.

---

<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:** [October 28, 2019, 5:48pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/12 "2019-10-28T17:48:29Z")

</div>

I am using the latest version (3.2.4). If you cannot open the app, try the following , it usually means you have to reset your app data:

[https://www.psychopy.org/troubleshooting.html#cleaning-preferences-and-app-data](https://www.psychopy.org/troubleshooting.html#cleaning-preferences-and-app-data)

---

<div class="post-metadata">

**Author:** ![CatK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/catk/32/6087_2.png) [@CatK](https://discourse.psychopy.org/u/CatK)\
**Post date:** [October 28, 2019, 8:01pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/14 "2019-10-28T20:01:21Z")

</div>

Thank you. I did what you recommended and now I can open the app now. But when I run it locally on my computer, it still gives me the message before the experiment gets to the trial section: File “C:\Users\cathe\Downloads\experiment\_testing 1\_lastrun.py”, line 462, in  
trialsLearn = data.TrialHandler(nReps=num\_learn, method=‘random’,  
NameError: name ‘num\_learn’ is not defined

Anything else that you’d recommend me to do? Mine is also 3.2.4 version

---

<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:** [October 28, 2019, 11:14pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/15 "2019-10-28T23:14:00Z")

</div>

This error is because you have not got the equivalent Python code that defines the “num\_learn” variable. In your image above, you have a code component with code type of “both”, showing the JS on the right, but no equivalent Python on the left. You just need to translate the JS to Pytho, and that error should be solved.It really depends on what you want to do though, if you only want to run it locally, use Python.

---

<div class="post-metadata">

**Author:** ![CatK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/catk/32/6087_2.png) [@CatK](https://discourse.psychopy.org/u/CatK)\
**Post date:** [October 29, 2019, 2:32am UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/16 "2019-10-29T02:32:02Z")

</div>

Thank you! I had Python code but removed it because it wasn’t working online and I was trying to debug. I now try to run it online. But although I was able to push it to gitlab, it doesn’t show on my dashboard. How can make it show on dashboard?

Sorry for the inconveniences. It’s my first time dealing with psychopy and i need to create an experiment that can be put online. Thank you for all your help!!

---

<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:** [October 29, 2019, 2:20pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/17 "2019-10-29T14:20:25Z")

</div>

Thanks @CatK, looks like this was an issue but was very recently fixed:

> [@Trouble Populating the Pavlovia Experiments Dashboard from Gitlab Projects](https://discourse.psychopy.org/t/trouble-populating-the-pavlovia-experiments-dashboard-from-gitlab-projects/9597):
>
> URL of experiment: [Sign in · GitLab](https://gitlab.pavlovia.org/lifelab/shift-task) Description of the problem: I am trying to host a js-psych task following the instructions on pavlovia ([Pavlovia](https://pavlovia.org/js-psych)) but none of the projects I have created on my pavlovia gitlab account seem to appear in the dashboard. My impression from the help document is that when a user creates an experiment project on gitlab that the dashboard should be automatically populated with a new unactivated experiment with the same name. Since I am very new to Pavlovia I am not s…

Would you mind recreating your project in another repository. To do this, you will first need to delete the .git folder in your project directory. It is a hidden folder though (preceded by “.” - as in `.git`), so you may need to set your folder options to view hidden files and folders.

---

<div class="post-metadata">

**Author:** ![CatK](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/catk/32/6087_2.png) [@CatK](https://discourse.psychopy.org/u/CatK)\
**Post date:** [October 29, 2019, 4:21pm UTC](https://discourse.psychopy.org/t/nameerror-when-using-javascript-on-builder/9592/18 "2019-10-29T16:21:53Z")

</div>

It finally works now! (Online too!) Thank you so much!!!
