| Reference | Downloads | Github

ReferenceError: position is not defined

URL of experiment:

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.

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:

// Begin Routine
PDot.setPos([PX, PY]);
1 Like

Thanks so much, it’s really apreaciated.

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]

I only now realized, after quite some time exploring the forum [e.g. @dvbridges here], 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 section 5.5.3 - Code Component, perhaps a new section 7.0 - Exporting your experiment to JavaScript)

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!

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!

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