Loading order of library JS files

I’m having a problem setting the loading order of generic JS files that contain library code. For instance I’ve just added Zepto to the project and want it to be loaded first, but dragging it in the window doesn’t make any difference - it stays where it was.

There is an error when I parse the file, presumably because the context is not right at that time, though clearly the library works fine when loaded as part of the system.

Can you create a tiny project that demonstrates this problem? Sometimes, I have created a new JS file, parsed it, and then pasted in the JS framework code that I want. That seems to get around having to parse code which generates some error or other.

Yeah pretty much every one of my files has an issue unfortunately apart from the actual PlayCanvas ones. Because they rely on libraries like lodash/mithril etc.

So you are saying you can’t modify the position in the Script Loading Order panel?

Yes some things move, some don’t. Also if I move things around including a “bad” file - then it doesn’t often stick.

Video:

Hi @whydoidoit I used to have the same issue when I was declaring variables/writing code (e.g. jQuery methods) outside of the default functions/classes that are tight to the “MyScript” object. Try commenting them out, parsing again the script and re-ordering.

A lot of these are libraries. I’ve tried commenting out stuff and parsing, but it’s locked this way now - can’t seem to figure what is tripping it up. I guess the editor should really trap out these errors to ensure that normal JS can work properly. Order is obviously very important in these files.

1 Like

Hey I don’t know if you guys have done something but the effect is different suddenly. Now I can reorder the items, but the loading order I specify is not being followed…

There is possibly an issue in UI with reordering, we will be looking into that.

Yeah, this is very frustrating, just spent an hour trying anything to get my new “configuration” script high up the order so it can delegate to others and remove the need for me to do this again and again, no luck though, it’s just stuck at the bottom.

Hi Mike,

Sorry for the frustration. We have a lingering bug where the script order list gets out of sync with the project and causes issues like this. Can you a few of these things:

  • Check to see if any scripts are missing from your scripts order list. If they are, toggle the preload checkbox on that script and it should be added to the order list.
  • If that doesn’t help, select all preloaded scripts, uncheck the preload option then re-check preload in the order you would like them to load.

Let me know if that helps.

Right they were all there, toggled preload and now they are in alpha order and still won’t reorder properly. It almost appears as if I’m moving the wrong script when I drag?

Can you send me your project id?

Sure it’s 450661. I’m just wondering if it’s because I have a script called application.js trying changing that right now

Nope not that, but changing it changed something, some of the top scripts now do reorder properly. The possible problem with that is that I had added a “resize” event to it which was causing a parser error due to the lack of the innerHeight variable in the parsing context.

Yep I’m definitely dragging a different script! But hard to work out which one to drag and to where…

So you have extension scripts running? Can you disable them and see if it works?

Hmmm, not sure I follow. Extension scripts?

You said:

Is that some local script running?

No it’s script for the running system. To resize something if the window changes size. I don’t want it running in the editor and I don’t believe it is. It’s just it throws an error parsing it.

To be fair, it throws errors everywhere parsing because I’ve got scripts that aren’t PC specific which need other things loaded in the right order to work - given when they are parsed for the editor nothing is loaded, many of these throw errors.

That was a rare example of a PlayCanvas script that parsed when I first added it and then stopped parsing because of the missing standard window property. Most scripts that throw parsing errors are just plain JS that expect an order. Like mithril-animate expects mithril. Several things need lodash etc.