# ReferenceError: position is not defined

**URL:** <https://discourse.psychopy.org/t/referenceerror-position-is-not-defined/7473>\
**Category:** Online experiments\
**Created:** [April 20, 2019, 12:11am UTC](https://discourse.psychopy.org/t/referenceerror-position-is-not-defined/7473 "2019-04-20T00:11:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![JackB](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@JackB](https://discourse.psychopy.org/u/JackB)\
**Post date:** [April 20, 2019, 12:11am UTC](https://discourse.psychopy.org/t/referenceerror-position-is-not-defined/7473/1 "2019-04-20T00:11:40Z")

</div>

URL of experiment:  
[https://pavlovia.org/run/Jbroome/do-cognitive-style-and-mood-mediate-attention-toward-emotional-faces/html/](https://pavlovia.org/run/Jbroome/do-cognitive-style-and-mood-mediate-attention-toward-emotional-faces/html/)

Description of the problem:  
Hi, i have recently attempted to upload my experiment online to Pavlovia. It is comprised of a mood induction and dot-probe task mainly made with builder but there are some code components. My problem is that after successfully uploading it and attempting to run it, i get a message saying ‘ReferenceError: position is not defined’. ‘Position’ only appears in my conditions file, to indicate the position of a stimuli, and in the actual position property of the aforementioned stimuli (written as $position) in order to dictate which position the stimuli should be in.

I did try removing it to see what would happen but then the same error came up again but concerning ‘pos\_poly’, the position of another stimuli. It appears pavlovia does not like code being in the position property box. Is there anyway to get past this error? Thanks

Edit: the first conditions file mentioned is accessed through the builders loop function which allows you to input conditions rather than through code I’ve input myself.

---

<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 23, 2019, 11:04am UTC](https://discourse.psychopy.org/t/referenceerror-position-is-not-defined/7473/2 "2019-04-23T11:04:53Z")

</div>

Hi @JackB, this is an error that has been reported previously and will be fixed in the next release of PsychoPy (3.1.0, which will be released within the next week or so). The problem occurs because the variables for your PDot positions are not defined until the trialhandler has collected the variables from the conditions file, and this happens after your PDot objects are created. So, when the PDot rect stim is initialised with the position variables, they cannot be found.

If you are unable to wait for the next release, a quick fix would be to manually set the position variables using a code component at the beginning of each routine. You would first need to create your rects with default positions e.g., [0,0]. Then, in a code component:

```javascript
// Begin Routine
PDot.setPos([PX, PY]);

```

---

<div class="post-metadata">

**Author:** ![JackB](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@JackB](https://discourse.psychopy.org/u/JackB)\
**Post date:** [April 23, 2019, 6:48pm UTC](https://discourse.psychopy.org/t/referenceerror-position-is-not-defined/7473/3 "2019-04-23T18:48:04Z")

</div>

Thanks so much, it’s really apreaciated.

---

<div class="post-metadata">

**Author:** ![tsgouvea](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tsgouvea/32/4983_2.png) [@tsgouvea](https://discourse.psychopy.org/u/tsgouvea)\
**Post date:** [May 1, 2019, 2:45pm UTC](https://discourse.psychopy.org/t/referenceerror-position-is-not-defined/7473/4 "2019-05-01T14:45:31Z")

</div>

I’m still facing this problem with PsychoPy v3-1-0. Specifically, task written in Builder runs smooth on my machine, but on Pavlovia ReferenceError pops up. Problematic reference is a variable with image name defined in ‘Begin experiment’ code block. I tried defining the variable once more at ‘Begin routine’ code block, but it didn’t fix it. [[task online](https://pavlovia.org/run/tsgouvea/tasksuite/html/)]

---

<div class="post-metadata">

**Author:** ![tsgouvea](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tsgouvea/32/4983_2.png) [@tsgouvea](https://discourse.psychopy.org/u/tsgouvea)\
**Post date:** [May 1, 2019, 3:52pm UTC](https://discourse.psychopy.org/t/referenceerror-position-is-not-defined/7473/5 "2019-05-01T15:52:54Z")

</div>

I only now realized, after quite some time exploring the forum [e.g. @dvbridges [here](https://discourse.psychopy.org/t/first-steps-in-online-experiments/5200)], that I’m supposed to manually translate code blocks from Python to JS (by setting dropdown menu “code type” to “both” on code block window). I’d suggest this be explained more prominently on documentation (e.g. [Manual](http://www.psychopy.org/PsychoPyManual.pdf) section 5.5.3 - Code Component, perhaps a new section 7.0 - Exporting your experiment to JavaScript)  
thanks!

---

<div class="post-metadata">

**Author:** ![CDawes](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@CDawes](https://discourse.psychopy.org/u/CDawes)\
**Post date:** [December 7, 2019, 10:37pm UTC](https://discourse.psychopy.org/t/referenceerror-position-is-not-defined/7473/6 "2019-12-07T22:37:29Z")

</div>

Hi all,

I just wanted to quickly add for anyone else that was stuck like me…

While PsychoPy can have the location set through a single variable such as stim.setPos(loca1), when translating this online Pavlovia requires it as two separate variables for each axis e.g., (e.g., loca1X, loca1Y).

I see dvbridges uses two variables in their example, but I didn’t realise there was a difference between online/offline so this confused me for a few hours!

Hope this helps!

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/b/0b7ff5ff1ed99feb1603c802eeba19f6e0a553b5.png)

---

<div class="post-metadata">

**Author:** ![Nuno](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nuno/32/7359_2.png) [@Nuno](https://discourse.psychopy.org/u/Nuno)\
**Post date:** [March 20, 2020, 7:04pm UTC](https://discourse.psychopy.org/t/referenceerror-position-is-not-defined/7473/7 "2020-03-20T19:04:10Z")

</div>

I am still having this issue. I am using PsychoPy v2020.1.1. I am trying to set up a simple experiment involving attentional cues - it was all prepared in builder with no code components and works fine in PsychoPy. When I try to run it online, I get the same message: “ReferenceError: X is not defined”, where X is a variable in my conditions file stating the position of some stimulus (both for cues and for targets).  
In the object properties (Polygon component) I already tried almost every combination I could think of in the position field: (Pos, 0), $(Pos, 0), (Pos, 0), [Pos, 0], [Pos, 0], [Pos, 0]; I also tried to speficy in my conditions file both coordinates (PosX and PosY) and write, in the position field: (PosX, PosY), (PosX, PosY), ($Pos, PosY), [PosX, PosY], [PosX, PosY], [$Pos, $PosY]. Nothing seems to work and everytime I get the same error message. Not sure if relevant, but I defined the units to “height”. Also, in this post I wrote “Pos” just as a general placeholder - I am actually using something like “PistaLoc”. I guess that I am probably overlooking something obvious and basic, but I am running out of ideas. Any suggestion would be welcome!

---

<div class="post-metadata">

**Author:** ![Lykanon](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@Lykanon](https://discourse.psychopy.org/u/Lykanon)\
**Post date:** [April 21, 2020, 8:13am UTC](https://discourse.psychopy.org/t/referenceerror-position-is-not-defined/7473/8 "2020-04-21T08:13:36Z")

</div>

I am experiencing the same issue using the most recent version (Psychopy v2020.1.3). Any update on this one or maybe a workaround using code @dvbridges?

Update: When I did a hard refresh in chrome (instruction to do this below) and defined the position with $[posX,posY] it worked.

Hard refresh: Open the Chrome Dev Tools by pressing F12. Once the chrome dev tools are open, just **right click on the refresh button** and a menu will drop down. This menu gives you the option of doing a hard refresh, or even clearing the cache and do a hard refresh automatically. ([https://support.piktochart.com/article/243-clear-browser-cache](https://support.piktochart.com/article/243-clear-browser-cache))
