ReferenceError when running study online

Hi All, I’ve encountered several Reference Error issues when trying to run the study in the browser from the Builder or from Pavlovia. Otherwise, it works on my machine.

To give an example, I’ve adapted a version of the code I found on this forum whereby participants can provide written responses by typing in text.

I initialize empty string in Begin Routine (i.e. captured_string=’’) to which all the pressed keys are added (through code I put in Each Frame). This is displayed on the screen every frame through setting “$captured_string+cursorVariable” (cursorVariable is just “|”).

When I run it online I get this error:

  • ReferenceError: captured_string is not defined

To give another example, I made a list with several pictures that I have to present at random positions on the screen (I tried both Begin Experiment and Begin Routine).

options = [‘astronomy.jpg’,‘car.jpg’,‘chemistry.jpg’, …….]
shuffle(options)

Then, on the screen I display them through:

$’folder_with_pictures/’+options[0]
$’folder_with_pictures/’+options[1]
etc.

Similarly, when I run the study online, I get the same ReferenceError: options is not defined

I get the same error each time I try to set the image/text through a variable like in these examples.

This error makes it impossible for me to run my experiment online using PsychoPy which is a shame because I’ve already learned to implement the paradigm using this software.

I would be very grateful if anyone would help me out find a way to fix this error!

What version of psychology are you outpouring the experiment from? Javascript (in the version we’re using) requires variables to be defined before use but the more recent versions of PsychoPy should detect and declare these auto-magically

I’m using PsychoPy v3.0.5

Looks like you have posted Python code above. Have you translated your code in your code components into JavaScript? If you have not written any JavaScript code in your code components, then this would also create this error, because options will not be defined.

If you have not translated your code, take a look at the code component, there is a drop down menu for “Code type”. You can select Py (Python), JS (JavaScript) or Both (Python and JavaScript panels side by side). The “both” setting is best for translation, allowing you to see both code types simultaneously.

2 Likes

Thank you so much David!

I implemented a small programme with options to test it out. I translated my code in JavaScript as you suggested and now it works online.

Hi @dvbridges,
I’m following this thread because I ended up with the same problem.
If I understand correctly, for any python code that I insert in the builder, I need manually write the translation into the corresponding JavaScript code. Is that right, or there is an automatic approach?

I’m using Psychopy 3.0.6, I have done my experiment with the builder, and I want to make it available online.

Thanks!

Michele

HI @rockNroll87q, yes you have to write the JS code manually (see above for directions using code component). The JS is not too different from Python code, and is easily convertable with the help of Google. We already have some example available on Pavlovia that demonstrate the use code components with Py to JS code translations. E.g., The Corsi blocks task and the BART task (Balloon Analogue Risk Task) – see Pavlovia.

1 Like