"win" not defined online

URL of experiment:

Description of the problem:
I’m building an experiment and have a continue button that I make using a code component in builder.
It works fine locally but when I try to run it it on Pavlovia I get a “win is not defined error”. So I assume it’s ahving an issue with my code to build the rectangle below. I’m using PsychoJS auto converter. Could something be going wrong with he JS code?

Python code:

polygon = visual.Rect(
    win = win,
    width=0.2, height=0.1,
    ori=0, pos=(0.65, -.4),
    lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
    fillColor=[1,1,1], fillColorSpace='rgb',
    opacity=1, depth=-1.0, interpolate=True)

JS code:

polygon = new visual.Rect({"win": win, "name": "polygon", "width": 0.2, "height": 0.1, "ori": 0, "pos": [0.65, (- 0.4)], "lineWidth": 1, "lineColor": [1, 1, 1], "lineColorSpace": "rgb", "fillColor": [1, 1, 1], "fillColorSpace": "rgb", "opacity": 1, "depth": (- 1.0), "interpolate": true});

Thanks for any help. If this doesn’t work, maybe I’ll switch to a spacebar press to continue.

Try setting the JavaScript win to psychoJS.window

New error: TypeError: Cannot read property ‘addChild’ of undefined

Here’s the change I made.

polygon = new visual.Rect({"win": psychoJS.window, "name": "polygon", "width": 0.2, "height": 0.1, "ori": 0, "pos": [0.65, (- 0.4)], "lineWidth": 1, "lineColor": [1, 1, 1], "lineColorSpace": "rgb", "fillColor": [1, 1, 1], "fillColorSpace": "rgb", "opacity": 1, "depth": (- 1.0), "interpolate": true});
text_4_Continue = new visual.TextStim({"win": psychoJS.window, "name": "text_4_Continue", "text": "Continue", "font": "Arial", "pos": [0.65, (- 0.4)], "height": 0.03, "wrapWidth": null, "ori": 0, "color": "black", "colorSpace": "rgb", "opacity": 1, "depth": (- 2.0)});

Just to check, should window be lowercase? Should there be brackets after? e.g. psychoJS.window()

Which win should I be changing in "win": win ?

So here’s an example of an object defined in the builder being defined in the automatically compiled javascript.

exampleRect = new visual.Rect ({
    win: psychoJS.window, name: 'speed_scale', 
    width: [0.1, 1][0], height: [0.1, 1][1],
    ori: 0, pos: [0.5, 0],
    lineWidth: 1, lineColor: new util.Color([(- 0.42), 1.0, 0.294]),
    fillColor: new util.Color([(- 0.42), 1.0, 0.294]),
    opacity: 1, depth: -3, interpolate: true,
	autoLog: false

With this as a template you should be able to figure out how to define one manually.

Thank you for your help!

Using psychoJS.window definitely fixes the win not defined problem.

I think I’ve narrowed down the error to my code that draws the rectangle. Which I have in the “Each Frame” tab of my code component.

If I remove polygon.draw(); I don’t get the error.
Is .draw the right method for drawing objects with JS? It worked fine locally in Python.

Is there a way I can see more builder compiled psychoJS code like what you show above?

Yes, just go to the code repository of any project you’ve sync’d to Pavlovia, open the “html” folder, and look at the [experiment name].js file. Or one of the publicly viewable repositories on Pavlovia.

Hi there,

I ran into the same error code when uploading my study to pavlovia, even though I did define the variable (but I am still relatively new to coding so maybe I did something wrong there)

This is the code that defines my ‘win’ in the python script

win = visual.Window(
    size=[1920, 1080], fullscr=True, screen=0, 
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[-1.000,-1.000,-1.000], colorSpace='rgb',
    blendMode='avg', useFBO=True, 

whereas when converting it to java it presents itself like this

// open window:
  fullscr: true,
  color: new util.Color([(- 1.0), (- 1.0), (- 1.0)]),
  units: 'height',
  waitBlanking: true

Would be grateful for any help on this.