# Project Script Global, when does it run?

**URL:** <https://forum.inductiveautomation.com/t/project-script-global-when-does-it-run/113416>\
**Category:** Ignition\
**Created:** [January 20, 2026, 4:14pm UTC](https://forum.inductiveautomation.com/t/project-script-global-when-does-it-run/113416 "2026-01-20T16:14:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [January 20, 2026, 4:14pm UTC](https://forum.inductiveautomation.com/t/project-script-global-when-does-it-run/113416/1 "2026-01-20T16:14:44Z")

</div>

Hi,

On top of my project scripts, where global variables are defined, i have the code below.  
When are global code being executed then?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/9/49fc2827c6e924decd033398d4faa6a4fdbcb00c.png)

---

<div class="post-metadata">

**Author:** ![Nol](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@Nol](https://forum.inductiveautomation.com/u/Nol)\
**Post date:** [January 20, 2026, 5:07pm UTC](https://forum.inductiveautomation.com/t/project-script-global-when-does-it-run/113416/2 "2026-01-20T17:07:17Z")

</div>

That's just the library where you define scripts. They do not run unless you call them. It's up to you to decide where and when.

For example you could go to the gateway events and set the scripts to run on startup or on a scheduled time. Or within a project you could have a button you click and then it runs the script.

If you haven't already the Inductive University has free modules you can watch to learn and there's a section about scripting.

> **[Learn Ignition at Your Own Pace](https://inductiveuniversity.com/)**
>
> Learn SCADA software (and get a credential!) for free with Inductive
> University’s online Ignition SCADA courses, taught by industrial automation experts.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [January 20, 2026, 5:43pm UTC](https://forum.inductiveautomation.com/t/project-script-global-when-does-it-run/113416/3 "2026-01-20T17:43:22Z")

</div>

> [@Nol](#):
>
> They do not run unless you call them. It's up to you to decide where and when.

Thats actually not true in this case. Because the script is not contained within a function definition, it will be excuted when the scripting engine starts. The variable will be available, but the value will be static (as in not changing).

However, @Eugene49 , this code will not be executed when the tag changes, it will run once, and `isEnable` will keep whatever the value of the tag is at that execution.

What are you trying to accomplish?

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [January 20, 2026, 5:49pm UTC](https://forum.inductiveautomation.com/t/project-script-global-when-does-it-run/113416/4 "2026-01-20T17:49:21Z")

</div>

> [@lrose](#):
>
> it will be excuted when the scripting engine starts. The variable will be available, but the value will be static (as in not changing).

I figure this is the case, only run once at the start.

> [@lrose](#):
>
> What are you trying to accomplish?

I have existing code that rely on global variables.  
These global variables is assigned manually before project is save.

I made a perspective view, so user can set global variable from the view.

I guess the solution is, replace all the code that refer to the global variable to a tag.read command.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [January 20, 2026, 6:14pm UTC](https://forum.inductiveautomation.com/t/project-script-global-when-does-it-run/113416/5 "2026-01-20T18:14:29Z")

</div>

No, you can certainly use a script variable, you just have to take steps to initialize and update it's value.

~~For instance:~~

~~ 

```python
isEnable = False

def initialize():
    isEnable = system.tag.readBlocking(["[defalut]Settings/ENABLE_SCRIPT"])[0].value

def updateIsEnable(value):
    isEnable = value
    system.tag.writeAsync(["[default]Settings/ENABLE_SCRIPT"]],[value])

```

 ~~

Then in your project start up script, call the `initialize()` function.

Anywhere you need to read the value you can access the variable dirictly.

```python
NewScript.isEnable

```

~~And anytime you need to update the value call `updateIsEnable()` with the new value.~~

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 20, 2026, 7:28pm UTC](https://forum.inductiveautomation.com/t/project-script-global-when-does-it-run/113416/6 "2026-01-20T19:28:58Z")

</div>

> [@lrose](#):
>
> For instance

No, those won't work. Within functions, `isEnable` is read-only by default, and assignments are only local to the function. See examples for the `global` **keyword** in python.

But note that proper caching is best achieved with a dictionary or similar object that can have inner elements assigned. The the initialization just creates the empty dictionary.
