Pavlovia giving "random not defined" error, despite random not being used

Description of the problem:

I created a working experiment in PsychoPy (using builder) and uploaded it to Pavlovia (URL: here). The experiment starts to run OK, but it crashes on the first trial when it hits a particular routine, giving me this error: * ReferenceError: random is not defined

The routine in question does contain some custom code, which I suspect is causing the problem, however the error does not make sense to me: the JS code for the experiment does not import or use random (or call random as a should-have-been-defined object), because I had already changed all instances of random (from the original python version) to Math.floor(Math.random() ... )

As a sanity check, I dug into the complied JS code (here) and I can’t see any instances of random being used, either as a function or an object. So, I don’t understand what is going wrong with the experiment.

How should I proceed / debug this problem?

Previous versions of your code do seem to include references to ‘random’. Have you tried clearing the cache in your browser? I think it’s possible the old version is still in the cache and that’s what’s being run.

Thanks for the tip - clearing the cache solved this problem!

For future users who encounter similar problems: in my case at least, it looks like you need to clear the cache every time you sync a new version. This might be because my code contains other errors (e.g. I used range at some point) - perhaps once the code is error-free I won’t need to clear cache every time I sync.

You’re welcome! Yes, it’s always a good idea to empty your cache after syncing (and before trying to run your newly synced version).

You may have experienced at other times that you didn’t need to clear your cache, and your browser just ran the newly synced version of your code anyway. However, I don’t think this has anything to do with the presence of errors. There are certain criteria that the browser uses to determine whether it’s okay to use the cached version of a certain page (or the resources on that page, like your .js code, stimulus files, etc.), to do for instance with the age of the cached version. So you may “get lucky” with one of those other criteria (e.g. if the cached version is weeks old, it’s likely your browser won’t use it). However, to be safe, it’s always best to just clear your cache.