psychopy.org | Reference | Downloads | Github

Problem when trying to run online "ReferenceError:assignment to undeclared variable textwelc" (probably due to JavaScript wrong translation?)

#1

Hello everyone!

I have developed an experiment in PsychoPy 3.1.0, and it works perfectly in my computer. The problem starts when I try to run the experiment online, through pavlovia.org. When I try to start the experiment, I get the message “ReferenceError: assignment to undeclared variable textwelc”, which has no sense, since textwelc is a text object in my experiment that is clearly defined (the welcome text).

The experiment is way big (it has like 300 pictures, and a total of 80mb in the folder that contains all the documents), but I do not think this should be a problem. I think the problem may be due to some inline, but I use very simple ones, so I do not know. The only thing I use as an inline is “import random” at the begining of the experiment, and a conditional for some stimuli to appear (in psychopy it is written “Disgust.getRating()!=None and Fear.getRating()!=None and Anger.getRating()!=None and Sadness.getRating()!=None and Happiness.getRating()!=None and Surprise.getRating()!=None”, which translated to javascript, I think it is “Disgust.getRating()!=null && Fear.getRating()!=null && Anger.getRating()!=null && Sadness.getRating()!=null && Happiness.getRating()!=null && Surprise.getRating()!=null”, thing that I modify in the html folder with the name of the experiment ending in .js).

Please, I hope you can help me if I am doing something wrong. Find attached my experiment. Thank you so much.

Best regards.

exponlinedef.psyexp (125.4 KB)

#2

I think the error is because of the inline code that you are using to conditionally present your images and you mouse as well. You would also have to convert the Python code in those snippets to JavaScript (e.g., replace and with &&). You can do the same thing with a code component, and will be easier for you to read and debug. When you remove the code from the components, remember to reset back to time durations from the dropdown menu.

#3

Hi! Thank you for your reply.

I already replaced “and” for “&&” and “None” for “null”, but it still does not work. Besides, the error I get is related to the first object that is presented in the script. It starts with the object “frameDur”, and if I delete this object from the js script, it tells me that the problem is in the next object (“textwelc”).

I do not think I fully understand your last suggestion referring to use a code component and reset back to time durations. You mean that, instead of inserting this little code that conditions the start and the stop of the mouse and the image in its component, I should use a new code component and insert this code here? Wouldn’t this result in the same problem anyway? Sorry but I do not understand, could you please give a more extended explanation?

Thank you so much for your help!

#4

I managed to make it work after some tinkering about.

Turns out that not all of the inline was generating errors. Even though the exact same snippet was being used (Disgust.getRating()!=null && Fear.getRating()!=null && Anger.getRating()!=null && Sadness.getRating()!=null && Happiness.getRating()!=null && Surprise.getRating()!=null), when it was being used as the condition required to start components (either mouse or image1) it worked just fine, but it created a “ReferenceError: Bool is not defined” error if used as the condition that stops a component (Hopefully that information is useful for future debugging when modifying online experiments).

#5

Great. Yes the Bool error has been fixed in the latest release (3.1.1):