psychopy.org | Reference | Downloads | Github

Variable not found error on Pavlovia but not local Psychopy

URL of experiment: https://pavlovia.org/run/hyang336/lifetime_experience/html/

Description of the problem: I have a simple experiment setup with 4 blocks of trials, in each block participants rate something about words. I also have catch trials in each block, whose presentation I control by defining 2 variables in my conditional file in the loop surrounding the whole block: real and catch. Then I pass these 2 variables to the numRep$ in the inner loop surrounding real trials and catch trials, respectively.

The problem is that when I try to run is online through Pavlovia, it gives me a “variable $real is not defined” error, despite it running perfectly locally.

I am using Psychopy v2020.1.3

@Haopei_Yang, try deleting the ‘$’ prefix of your loop variable - it looks like the dollar sign has been written into your JS code, which is causing the error.

That didn’t work, got exactly the same error.

You probably need to refresh your browser cache, using Shift + F5, or something else depending on your OS - see link.

Now it just got stuck at “initializing the experiment” forever

There must have been a compile error when you exported the HTML, did you get an error message in the dialog box of PsychoPy?

and if I add back the sign then refresh the cache I get the same error, so I think the missing sign is causing it to hang on initialization.

If there is an error it shouldn’t let me to run it right? But I could run it locally with or without the $ sign and I don’t see any error when I run it locally.

I think the issue is using variable called catch - this is a JavaScript key word used for try, catch error handling. This would work in Pythin, since catch is not the name of a built-in keyword. Changing the name from catch as a variable to something else, e.g., catchLoop, should remove that particular error.

That doesn’t work either. I changed the variable names from real to real_trial, catch to catch_trial. Then refreshed the cache and tried to run with or without the $ sign. Both give the same error, either “real_trial is not defined” or “$real_trial is not defined”.

Ok, did you remove the dollar signs from all of your loops? Making the changes above worked in this example (note, you also have to change the names in your conditions file):

https://run.pavlovia.org/dvbridges/test_lifetime/html/

Yes the sign is removed from all loops, and I changed the name in the conditions file. I also reloaded the condition file so that in Psychopy it shows the variable names have changed to real_trial and catch_trial. But still the same error appeared. I just resynced the code. If you run it now you should see that there is no sign in the error msg.

Thanks, did you change the name of the variable in the conditions.xlsx file? Btw, you did not need to change real, only catch. Here is my example, with only the fixes mentioned above:

pilot.psyexp (78.8 KB)
conditions.xlsx (8.6 KB)

Yes I changed the name of the variable in the conditions.xlsx file. I just downloaded from the repo and verified that they are indeed changed. The only difference between your file and my up-to-date file is that I named it to catch_trial instead of catches, and I also changed the real variable to real_trial. But I don’t think those two are also key words in JS.

Ok, well ll I did was remove the $ signs from the variable names, and changed catch to catches in both the conditions file, and the loops. The example will work, so if you can make those changes, resync with Pavlovia, and refresh your browser cache, things should work:)

When you say example, you are not referring to my experiment right? Have you been able to run my experiment without the error? I have not tried other examples but I tried all these to my experiment. It just does not work, and the same error message persists. I made the project public so you should be able to verify that I removed all the dollar signs in my loops and made the suggested changes to the condition file.

Also one of my colleagues said that she just ran it on Mac without error, so it appears to be OS dependent.

That error has disappeared today without me doing any more change. I think what was causing the issue is that when you run the experiment through Pavlovia it does not actually run the most up-to-date version in the repo. I have since made another minor change in my experiment, but that was not reflected in the online experiment for like an hour despite my cache refreshing.

@Haopei_Yang, the files I posted were the fixed versions of your task.

Weird, I guess either removing the dollar sign or changing the variable name fixed the error, just need to wait for Pavlovia to update the changes. I will mark a solution.