Dependency between add on script.

Typically: "How do I... ", "How can I... " questions
Post Reply
DrRiften
Posts: 9
Joined: 06 Jun 2024, 13:36

Dependency between add on script.

Post by DrRiften »

I'm writing some tools that can be used cross different scenes through add on script. And call add on functions through sim.getScript and sim.callScriptFunction.

It seems that an add-on script can also call functions from another script. However, the source script must have been loaded and initialized. I wonder if I can manage the order of add-on initialization so that the base script is always initialized when used by another add-on? Or if there are other ways to manage the dependency between scripts?

By the way, how is sim.callScriptFunction implemented? Does it call functions through remote communication or not?
coppelia
Site Admin
Posts: 10722
Joined: 14 Dec 2012, 00:25

Re: Dependency between add on script.

Post by coppelia »

Hello,

as of now, you can't specify the load and initialization order of add-ons. You'll have to implement some messaging between your add-ons in order to make sure all required are loaded. Simplest would be to try with a protected call sim.callScriptFunction: if the call fails, the target add-on (e.g. the service add-on) was not yet initialized.

sim.callScriptFunction happens immediately without communication overhead if both scripts run in Lua. Otherwise the call is implemented under the hood via interprocess communication.

What you can also do is modify the sandbox script (which is initialized first) and call relevant functions in the sandbox.

Cheers
DrRiften
Posts: 9
Joined: 06 Jun 2024, 13:36

Re: Dependency between add on script.

Post by DrRiften »

coppelia wrote: 11 Jun 2024, 07:19 Hello,

as of now, you can't specify the load and initialization order of add-ons. You'll have to implement some messaging between your add-ons in order to make sure all required are loaded. Simplest would be to try with a protected call sim.callScriptFunction: if the call fails, the target add-on (e.g. the service add-on) was not yet initialized.

sim.callScriptFunction happens immediately without communication overhead if both scripts run in Lua. Otherwise the call is implemented under the hood via interprocess communication.

What you can also do is modify the sandbox script (which is initialized first) and call relevant functions in the sandbox.

Cheers
Thank you for your reply. Is there any update plan for such a feature? Either a script loading API or something like an add-on manager?
coppelia
Site Admin
Posts: 10722
Joined: 14 Dec 2012, 00:25

Re: Dependency between add on script.

Post by coppelia »

There is no immediate plan for modification in that regard. Have also a look at the add-on addOns/Point sampler service.lua which provides various functionality to other add-ons.

Cheers
Post Reply