psychopy.org | Reference | Downloads | Github

Which PsychoPy functions and variables are available in PsychoJS?

URL of experiment: 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

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

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:

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.

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.