# Project and shared scripts - scripting outside of functions

**URL:** <https://forum.inductiveautomation.com/t/project-and-shared-scripts-scripting-outside-of-functions/19701>\
**Category:** Ignition\
**Created:** [September 17, 2018, 8:40pm UTC](https://forum.inductiveautomation.com/t/project-and-shared-scripts-scripting-outside-of-functions/19701 "2018-09-17T20:40:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [September 17, 2018, 8:40pm UTC](https://forum.inductiveautomation.com/t/project-and-shared-scripts-scripting-outside-of-functions/19701/1 "2018-09-17T20:40:34Z")

</div>

I’ve only used project & shared scripts by referring directly to a function inside them. I know you can declare variables outside of the functions, but when does that declaration run?

To clarify, lets say I have a function in a script that I’d access by shared.TestLibrary.doFunc(). If I had lines in the script called “TestLibrary”, when would they actually run? I think I’ve seen it used before but can’t find it.

---

<div class="post-metadata">

**Author:** ![salbrechtsen](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/salbrechtsen/32/18660_2.png) [@salbrechtsen](https://forum.inductiveautomation.com/u/salbrechtsen)\
**Post date:** [September 17, 2018, 8:58pm UTC](https://forum.inductiveautomation.com/t/project-and-shared-scripts-scripting-outside-of-functions/19701/2 "2018-09-17T20:58:43Z")

</div>

I’m not sure how ignition handles this, but in general if I have 2 files:

_import\_file.py_  
`print "hello"`

\*main\_file.py"  
`import import_file.py`

When main\_file.py is run, the result will be “hello”. This is due to python being an interpreted vs compiled lanugage. I’m not sure how this is impacted with Jython and Ignition. You could run this same test in ignition though.

---

<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:** [September 18, 2018, 4:01am UTC](https://forum.inductiveautomation.com/t/project-and-shared-scripts-scripting-outside-of-functions/19701/3 "2018-09-18T04:01:18Z")

</div>

The entire script module is executed upon first reference, including assignments and the def statements that place place the functions into the script module’s namespace alongside the assignments. The namespace persists in the client until the client is restarted. It persists in the designer until the project is refreshed/opened. It persists in the gateway until some event requires an update to scripting, like when a script is saved from a designer or a module is loaded/unloaded.
