How do I adjust the calling order of onFirstSceneLoaded functions for multiple extensions?

My game has two extensions as shown in the image below.
All of those extensions have the onFirstSceneLoaded lifecycle function.

image

However, the onFirstSceneLoaded functions are being called in a different order than I intended. I want CommonUtils’s onFirstSceneLoaded function to be called first because TetrisUtils’s onFirstSceneLoaded use internally CommonUtils’s functions, but TetrisUtils’s onFirstSceneLoaded function is called first.

How do I adjust the calling order of onFirstSceneLoaded functions for multiple extensions?

Should I change the order of the extensions described in game.json directly with a text editor?
Please tell me anything.

Right click on 3dots button and move up

I tried as you told but CommonUtils is still called after TetrisUtils.

image
image

If it were me I would move all of your “OnFirstSceneLoaded” logic for each extension into a new function called “init” or something like that. Then in “CommonUtils” add a new OnFirstSceneLoaded block that calls “init” in order on each of your extensions. This way you don’t have to rely on the internal call order.

1 Like

Yes, it’s possible to do that. But I don’t want to deal with any specific business logic in “CommonUtils”.

What is the basis for the order in which the extensions’ onFirstSceneLoaded are called?

I think the order is linked to the naming of the extension. Maybe in alphabetical order or reverse alphabetical order.

1 Like

It turns out that it’s not related to the alphabetical order :disappointed_relieved:

image

image

I think the extension’s priority to be loaded should be configurable so that it can be changed.

I eventually decided to follow a similiar way that @krunkster suggested. it’s because it seems more reasonable not to depend on the internal calling order. So I added another extension named Start-Up and its onFirstSceneLoaded calls other extensions’ initialize functions as follows. Thank you all :grinning:

In what order are the extensions in the game file?
The loading order should have a logic^^

The order of the extensions in the game file corresponds the order defined in “Project Manager> Function/Behavior”.

In my opinion, it also needs another variable concept that can only be used in extensions(Extension Variable). VisualScript that uses scene or global variables is shorter than JavaScript (because it doesn’t have to use runtimeScene.getObject…), but if that variable is only used for VisualScript within an extension, there is a problem that it consumes the scene or global name space.

The method I mentioned using the startup extension doesn’t work. I’m just going to manually call the Initialize action of each extenion in the first scene. :cry:

An idea for the loading order of extensions @4ian ?

normally, the extension files should be loaded in alphabetical order, as every function is exported as a JS file with the name of the extension and of the function and is used as a normal JSExtension include, so I don’t get why it isn’t the case

Extensions loading order is unspecified. In practice, avoid as much as possible relying on the initialization of other extensions.

Note that in the future we could add something to allow extensions to explicitly declare a dependency on another extension, and then ensure extensions are loaded in the reverse order of dependency (we first load the extensions that are dependencies of others) (that’s called a “topological order”).
We would also need to prevent circular dependencies, and maybe automate this so that you don’t need to make this list of dependencies by yourself if you’re just using traditional actions/conditions.

3 Likes