On which hardware are global 'shared' scripts executed?

If a client is calling a function in the global script library (e.g. ‘shared.MyScript.myFunc()’) does this code execution occur on the client PC or on the Gateway?

Thank you!

It depends where you’re calling from… functions in the global scope are available to both gateway and client.

It’s being called from a client event script. I just want to make sure that the execution is on the client PC, not the Gateway server as many different client projects will utilize this same helper function.

It will run in the client if called from a client event script.

Shared scripts are just a library you can create. Similar to all system.* functions, they are just executed from where they’re called.

It’s even so that on the server, the scripts can be executed in different scopes that don’t share a state. F.e. when you call a script from a “Value Changed” tag event, and set a variable in the script, the variable won’t be set if you call the script from a gateway event.

Thus it’s best to limit yourself to static functions only (functions that don’t hold a state).

Otherwise you need to take into account when the state can disappear (f.e. when the script gets reloaded) or which scopes can be different. If you do need to store a state, it’s probably best to store them in memory tags (that makes them quite easy to check too, so you can debug). Of if you need to store complete objects that are difficult to map to memory tags, try adding them to the ignition globals (system.util.getGlobals).

1 Like