# Creation of Instance Object

**URL:** <https://forum.inductiveautomation.com/t/creation-of-instance-object/72444>\
**Category:** Ignition\
**Created:** [April 14, 2023, 4:50am UTC](https://forum.inductiveautomation.com/t/creation-of-instance-object/72444 "2023-04-14T04:50:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [April 14, 2023, 11:18am UTC](https://forum.inductiveautomation.com/t/creation-of-instance-object/72444/2 "2023-04-14T11:18:05Z")

</div>

Ignition **event** scripts generally do not hold state--that is, any variables/functions/classes created in the script are discarded at the end of the script.

Ignition **project library** scripts, on the other hand, are ~~run **once** at the top level the first time they are referenced elsewhere~~ , and then persist until the project is edited/saved (or an parent project is edited/saved).

Put your import and your initialization of `pid` in the top level (unindented) in a project library script. Put the call to _execute_ the instance in a **function** within the project library script. That function would use `system.tag.readBlocking()` to retrieve the process value into a local python variable for the `pid` instance to use, and would use `system.tag.writeBlocking()` to send the control value to an output tag.

Call that **function** from a gateway timer event at the desired pace.

Edit: Oy! Library script auto-import is racy, and doesn't **always** run once. ☹ Use the work-around here until it is fixed:

> [@Project Library Script Initialization Races](https://forum.inductiveautomation.com/t/project-library-script-initialization-races/98636):
>
> Are you annoyed by pseudo-random breakage in Ignition project library scripting? Odd top-level constants being garbled, or operations in the top level that have side effects running twice? Or more? Not happening much, but always around project edits, and sometimes even on gateway restart? Yeah, me too. frowning_face Poking around under the hood back in the spring, for a module development task, I ran across some problematic IA bytecode and pinged some people. But it went nowhere, as I co…

---

_[View the full topic](https://forum.inductiveautomation.com/t/creation-of-instance-object/72444)._
