__start__.js as a function

When creating a web-package download from the publishing option, the archive has a file called start.js. This file contains an automatically self-invoked function. The JavaScript file is then included into the project within the index.html, could I suggest that this is not a self-invoked function.

We’re developing an app where we need to take control of when this function is invoked, but it is not possible as-is. At the moment I’m just replacing ‘start.js’ with my own copy that has been modified to be a callable function. But this is not really future-safe and leaves me feeling a little nervous :slight_smile:

If it were a callable function by default, then it only leaves me to worry about injecting my code into the html and I can keep the default ‘start.js’ file without having a custom copy. Not super urgent, just would be useful.

*note, the filename should have two underscores on either side, but the text printing thinks I want the name bold instead.

Just to verify, do you actually need to control when that function in start.js gets called or more that you don’t want the main content of the application to start until an external event is triggered?

The reason I ask is that you could have the application load to a splash or holding screen until it receives that external event to progress onto the main content?

Hi Steven,
It’s more that I’d like to control when that function is called. We are running within another third-party framework and we’re not supposed to begin any processing until they have told us it is time to do so.

It maybe that I’m misunderstanding the second part of your message sorry, as it reads like the behaviour I am looking for :slight_smile:


I don’t know what the 3rd party’s definition of ‘processing’ is so my proposed workaround could still work pending on their wording.

What I’m saying is that your app when page loads, it loads as normal but doesn’t do anything beyond show a holding image or message. Once you are ready to ‘process’, then you can fire an event to the app to start processing whatever it needs to do.

As an example, think of game that when it loads, it starts on the title screen and doesn’t start playing until the user presses the start button.

Another example, this sample won’t load any of the assets till the user presses the space bar:
Run: http://playcanv.as/p/MGKfj6jm/
Overview: https://playcanvas.com/project/436584/overview

You can do something similar except trigger the load via an external event on the page.

Is that making more sense?

Yes, that clarifies it thank-you.

Is this preloader.js script automatically detected or should it be placed in the script priorities list (I am unable to open the script priorities in the example)? Does the presence of this file prevent the automatic loading of resources (that might seem a silly question, just want to be sure).

It looks like it might be suitable, thanks.

You should be able to just double click on it from the assets window (if that doesn’t work, please let me know but as a workaround, you can just fork the project).

TBH, you don’t really need a preloader. The sample is more to show you that you can prevent certain entities being shown/processed/etc until an event takes place (in that sample case, the user presses space bar).

You just need a mechanism in place that doesn’t start the processing until the the external event is triggered. A simple FSM would suffice.

So as quick and dirty another example, you could put everything as a child of one entity, disable that entity in the editor so when the app starts, none of the scripts in the children update. And then enable that parent entity when the external event is fired.