# On which hardware are global 'shared' scripts executed?

**URL:** <https://forum.inductiveautomation.com/t/on-which-hardware-are-global-shared-scripts-executed/17001>\
**Category:** Ignition\
**Created:** [February 15, 2018, 3:30pm UTC](https://forum.inductiveautomation.com/t/on-which-hardware-are-global-shared-scripts-executed/17001 "2018-02-15T15:30:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschell1978](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mschell1978/32/8996_2.png) [@mschell1978](https://forum.inductiveautomation.com/u/mschell1978)\
**Post date:** [February 15, 2018, 3:30pm UTC](https://forum.inductiveautomation.com/t/on-which-hardware-are-global-shared-scripts-executed/17001/1 "2018-02-15T15:30:15Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 15, 2018, 4:36pm UTC](https://forum.inductiveautomation.com/t/on-which-hardware-are-global-shared-scripts-executed/17001/2 "2018-02-15T16:36:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mschell1978](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mschell1978/32/8996_2.png) [@mschell1978](https://forum.inductiveautomation.com/u/mschell1978)\
**Post date:** [February 15, 2018, 5:10pm UTC](https://forum.inductiveautomation.com/t/on-which-hardware-are-global-shared-scripts-executed/17001/3 "2018-02-15T17:10:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 15, 2018, 5:28pm UTC](https://forum.inductiveautomation.com/t/on-which-hardware-are-global-shared-scripts-executed/17001/4 "2018-02-15T17:28:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [February 16, 2018, 7:00am UTC](https://forum.inductiveautomation.com/t/on-which-hardware-are-global-shared-scripts-executed/17001/5 "2018-02-16T07:00:15Z")

</div>

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).
