# Which PsychoPy functions and variables are available in PsychoJS?

**URL:** <https://discourse.psychopy.org/t/which-psychopy-functions-and-variables-are-available-in-psychojs/10773>\
**Category:** Online experiments\
**Created:** [January 29, 2020, 8:07pm UTC](https://discourse.psychopy.org/t/which-psychopy-functions-and-variables-are-available-in-psychojs/10773 "2020-01-29T20:07:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guido\_Biele](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/guido_biele/32/6123_2.png) [@Guido\_Biele](https://discourse.psychopy.org/u/Guido_Biele)\
**Post date:** [January 29, 2020, 8:07pm UTC](https://discourse.psychopy.org/t/which-psychopy-functions-and-variables-are-available-in-psychojs/10773/1 "2020-01-29T20:07:10Z")

</div>

URL of experiment: [Pavlovia](https://pavlovia.org/guido.biele/testjs)

Description of the problem: I have (lots of) python code and don’t know which functions PsychoPy can be used in javascript code. For example, this

```auto
Q_checkboxes = []
Q_ypos = [.1, 0, -.1, -.2, -.3]
Q_name = ['Checklist','DEQ','State','StateChangeTask','StateChangeDrug']
for (let i = 0; i < Q_name.length; i++) {
    Q_checkboxes.push(
    visual.Rect(
    win=psychoJS.window,
    name= Q_name[i],
    width=(.05, .05)[0], height=(.05, .05)[1],
    ori=0, pos=(0.1, Q_ypos[i]),
    lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
    fillColor=[1,1,1], fillColorSpace='rgb',
    opacity=1, depth=-8.0, interpolate=true)
    )
    }

```

is hopefully valid javascript for PsychoPy/Pavlovia, but when I try to run it, I get the error message

> ReferenceError: win is not defined

I had hoped that `win` would be automatically generated, as it is for an ordinary PyschoPy experiment. When I checked the javascript script, it looked as if `psychoJS.window` corresponds to `win` in PsychoPy, but I am not sure, because I am still getting the same error.

So my general question are:

- Are functions like `visual.Rect` included in the PsychoJS library? (I couldn’t find rectangles on [Status of online options — PsychoPy v2023.2.3](https://www.psychopy.org/online/status.html), but they seem basic to me.)
- Where can I find some more information about how to adapt PsychoPy experiments with lots of python code for pavlovia?

My specific question is, what the reason for the error message above is.

Best, Guido

PS: I think it would be good if the PsychoPy websites were much clearer about the fact that adding code to builder experiments makes running those on pavlovia much more difficult.

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [January 29, 2020, 8:25pm UTC](https://discourse.psychopy.org/t/which-psychopy-functions-and-variables-are-available-in-psychojs/10773/2 "2020-01-29T20:25:32Z")

</div>

> [@Guido\_Biele](#):
>
> PS: I think it would be good if the PsychoPy websites were much clearer

PsychoPy is an open source collaboration and certainly welcomes contributions from users. If you find ways the documentation can be improved, then you can fork the repository on Github and issue a pull request to have your suggestions added. For example, here is where you would find the source code for the online documentation:

> <https://github.com/psychopy/psychopy/tree/release/docs/source/online>
>
> //github.com/psychopy/psychopy/tree/release/docs/source/online

> [@Guido\_Biele](#):
>
> the fact that adding code to builder experiments makes running those on pavlovia much more difficult.

There might be better ways of expressing that. Adding code to Builder experiments, whether in Python or Javascript, adds functionality that Builder itself doesn’t provide automatically. Adding custom code is necessarily “harder” than just selecting options in the graphical interface, but I’m not sure how that is specific to the online environment. And in fact, PsychoPy will soon provide an automated translation tool that will go at least some way to convert custom Python snippets to Javascript, making the process even easier.

---

<div class="post-metadata">

**Author:** ![Guido\_Biele](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/guido_biele/32/6123_2.png) [@Guido\_Biele](https://discourse.psychopy.org/u/Guido_Biele)\
**Post date:** [January 29, 2020, 10:09pm UTC](https://discourse.psychopy.org/t/which-psychopy-functions-and-variables-are-available-in-psychojs/10773/3 "2020-01-29T22:09:44Z")

</div>

Hi Michael,  
I appreciate that PsychpoPy is an open source project and have much respect for the developers. My initial post probably has not made that clear, and I am sorry if my PS came over as unfriendly. This was not my intention.

I would in fact say that if one has a bit programming experience, adding things to an experiment with (python) code is easier and faster than doing things with drag and drop in the Builder.

I’m busy the next days trying to get things running on pavlovia, but I’ll make a PR to the documentation.

In the meantime, i hope somebody who knows PsychoJS finds some time for one or more quick pointers.
