| Reference | Downloads | Github

Issues With Debugging PsychoJS files

Description of the problem:

I just uploaded my experiment to Pavlovia. When I go to pilot it, I get the following error (see bottom). Everything works fine through the PsychoPy GUI. If I try to run the files through a different Server (e.g., Live Server), I get a different error. numReps is one of the first variables I define. In fact none of the variables I define during my initialization are present anywhere in the JS file. What should I do?


Hi @jwhenry28, it would be useful if you could share the URL to your task, but one explanation for this error could be the use of code components. If you have Python code in a code component, you will have to translate the Python code to JavaScript manually. To translate the code, open your code component dialog and select the code type as “Both”, so you can see Python and JavaScript panels on the left and right, respectively. Now you can see the Python code in the left panel, and you can type in the equivalent JavaScript in the right panel. JS is not so different from Python, so translating the code will not be too challenging.

Thanks for the advice. The link to the git code of my experiment may be found here.

Additionally, I started to convert the python to JS manually. I converted the first bit of code that I had in the first block (which was triggering the numReps error), but the error persists. Puzzled, I looked at the code on github and found this:

 // number of study items, etc
  const numItems = 60;
  const numCates = 4;
  const numReps = numItems / 2;
  const numPairTypes = (numCates * (numCates - 1)) / 2; // permutation

Yet, I am still getting the “numReps not defined” error. What is my mistake?

I think I have figured it out. Looking at the source JS code on gitlab, I can see that the variable numReps is declared within the experimentInit() function. However, it is not saved in any way so when it is called again in the outerLoopLoopBegin() function, I believe its lifetime has ended. How do I ensure that each variable which is defined at the beginning of the experiment remains in scope throughout the experiment?

Yes, this is done by not declaring your variables using const or var. PsychoPy will find any variables used, and declare them with global scope. If you do this yourself, it limits the variable scope to one part of the experiment e.g., the experimentInit function. So to fix, remove any manual use of const or var e.g.,

 // number of study items, etc
  numItems = 60;
  numCates = 4;
  numReps = numItems / 2;
  numPairTypes = (numCates * (numCates - 1)) / 2; // permutation

Thanks! That helped to solve that problem. But I am now having issues with displaying my images on Pavlovia. I’ve posted more information about it here.

I appreciate the help! Please excuse my obvious shortcomings.