Code error generated that appears false

I used identical code in another experiment that is generating errors in another experiment, so it may be a read herring
sum=function(arr) {

If other can see an actual problem, I am throwing in the towel. I copy+pasted from the working experiment. I do not see how this could be the error, but maybe I’ve been looking at it for too long!

Most of that code isn’t needed any more.

However, is the error due to the space between function and ( ?

Apologies, that added space was one of the permutations trying to find any mistake. This is the identical text, which resulted in an error, despite running without error (in identical form) in the other experiment.

The error still seems to point clearly to this line, despite it running in the other experiment. The code is identical between the two, but only 1 runs.

sum() now auto translates correctly, so I would highly recommend disabling your code_JS. You might need to click into other code components to update their translations if they haven’t been touched since version 2022.

I have been disabling the code, which allows the experiment to run locally. However, I continue to get a variety of error messages of unclear source. This one, I believe, refers to the “disabled” code, despite that it is disabled:


I think it is coded as javascript, but trying to call a python function. But it previously worked.

The online error given is consistent with the np function not being able to be called, but it’s disabled. It shouldn’t be trying to call it.

How is it disabled?

If you switched an Auto code component and changed it to Py the JS code might still be there. Change to Both and delete the JS.

I used the “disabled” check in builder:

I deleted all the (data folder, js, etc.), changed the code to “Both”:

and I’m back to an error in that code, which does not seem to be an actual error

and is pasted from working code here:
Is there a way to skip the dialog box when running online? - #4 by Luke

var checkOK = setInterval(function() { //Use basic nested setInterval for Status check of dialog
    console.log("Check if DialogBox loaded");
   if (document.getElementById("progressMsg")) { //Wait for ProgressMsg to exist
        console.log("Dialogbox exists."); //Dialog Box Ready
      var statusText = document.getElementById("progressMsg").innerHTML; //get Status of ProgressMsg
      if(statusText == "all resources downloaded.") //If status is good. Go and let JS Click the button
      {
      console.log("All resources were downloaded! Press Ok now...");
      document.getElementById("buttonOk").click(); // Click on the checkbox
      clearInterval(checkOK);
      }
   }
}, 500); // check every 500ms

I appreciate the attempts to help! It was running perfectly for a week, and clearly some tweak has caused havoc.

That code is JS for use online and will give an error locally. It doesn’t reference np so it isn’t the code component causing the np error.

Am I understanding correctly that disabling components in Builder they are still included in JS in Pavlovia uploads? If so, I know that code was running, so I will just pull it completely until I get other coding resolved.

This is the only occurrence of np, which was a function:


I tried changing the code type to Python (same error). It runs locally, it fails online.

I tried changing the command to numpy.random.poisson (maybe a library updated on me without backcompatibility?), which caused failure to run locally.

I tried to re-paste with np.random.poisson to re-translate Auto->JS. I deleted the existing scripts (.js, etc). Again, it runs locally and gives the np error when attempted to run online.

I have checked for errant space. There are no quotations that could be wrong. This exact code ran without error online two weeks ago, so I am still suspicious this may not be the actual error, despite it appearing in the error message.

If the component is disabled then it shouldn’t appear in the latest JS code. I’m assuming that you know how to run the latest code online

np.poisson is your error. You can’t use that online. I’m on my phone so I’m not going to look for possible JS equivalents for you. One alternative would be to sample from a list generated in Excel (or Python) using a Poisson distribution that you’ve hard coded in the experiment. Shuffling 100 values or so should be sufficient in most cases.

Thanks, I will check some possible js alternatives. Hard coding if necessary!

Is “You can’t use that online.” something specific to this function? Or a type of functions? I will code with exceptions in mind in the future, if I know what to work around.

Python libraries such as numpy can’t be used online.

Have a look for my crib sheet and online troubleshooting guide. The latter is on the site help pages.

Oh, wow I had not even thought about numpy not being able to be called ever! For others who may be looking, this is the crib:

The relevant section

Just part of the painful learning process. I’m still glad to have Pavlovia, but ouch. :sweat_smile:

Final autopsy.

I was working on the setup_code in python, the language I know. I used Auto->JS to have it recreate the javascript. The javascript it created was not accurate and did not run.

The js for np.random.poisson() can be coded as:
iti_dist=[].concat(Array(10).fill(0), Array(32).fill(.5), Array(28).fill(1), Array(18).fill(1.5), Array(6).fill(2), Array(4).fill(2.5), Array(1).fill(3));

On uploading, I did have the very common error Platform:Unknown:
image

By selecting Running, this updated automatically:
image

The code then gave the same old message (np not defined). I cleared cache. I got a new error, that “Range is not defined”. This turned out to be the same issue as above, the auto-generated JS from the python was gibberish and needed to be written. This happened with shuffle and some other functions that did not translate from the Python using auto->JS. I now have a new error, so it is still not running.


The original from which this was pulled was running np. and similar, so it remains unclear what happened that this stopped working. At least there is a path forward now? Maybe?

The good news is, if you are running a laboratory in person, you probably will not need to do any of this.

I ended up using a combination amalgam of Javascript mess to get conditions into characters that could be read (and still replacing the numpy code, which cannot be loaded in online experiments):

        function list(s) {
            // if s is a string, we return a list of its characters
            if (typeof s === 'string')
                return s.split('');
            else
                // otherwise we return s:
                return s;
        }
        conditions = list(util.range(1, 18, 1));
util.shuffle(conditions);
blockCounter = 1;
nBlocks = 2;
iti_dist=[].concat(Array(10).fill(0), Array(32).fill(.5), Array(28).fill(1), Array(18).fill(1.5), Array(6).fill(2), Array(4).fill(2.5), Array(1).fill(3));
maxTrials = 30;