# Gateway event occasionally error when execute Project libary script : NameError: name is not defined

**URL:** <https://forum.inductiveautomation.com/t/gateway-event-occasionally-error-when-execute-project-libary-script-nameerror-name-is-not-defined/92012>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [June 18, 2024, 12:26pm UTC](https://forum.inductiveautomation.com/t/gateway-event-occasionally-error-when-execute-project-libary-script-nameerror-name-is-not-defined/92012 "2024-06-18T12:26:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [June 18, 2024, 12:26pm UTC](https://forum.inductiveautomation.com/t/gateway-event-occasionally-error-when-execute-project-libary-script-nameerror-name-is-not-defined/92012/1 "2024-06-18T12:26:27Z")

</div>

I have created a script in my project libaray, and I am executing it in my Gateway Event - Timer, so that the script runs every second.  
Usually, it works well, but there are occasional errors says the name is not defined.  
But the Function name is defined well like mentioned, it only has error occasionally, like 5-10 times 24 hours.

The script itself is fairly simple, involving some calculations.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/f/af1424b0e3a0ea3a07e2ab2fc4a2d98a1b906789.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/f/3fbc5fd0903927862f60a039193b44ecd1ec3ec7.png)

And this issue is not just for one Gateway event, quite a few report similar errors.  
I suspect this related to gateway event timer frequency, but no idea how this can be improved.

---

<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:** [June 18, 2024, 12:30pm UTC](https://forum.inductiveautomation.com/t/gateway-event-occasionally-error-when-execute-project-libary-script-nameerror-name-is-not-defined/92012/2 "2024-06-18T12:30:57Z")

</div>

Is the project in question being edited frequently? Or one of the projects it inherits from? If so, it may be a script library race condition I reported recently, and you should also report to IA support. (It is hard to reproduce--your case may help.)

---

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [June 18, 2024, 12:36pm UTC](https://forum.inductiveautomation.com/t/gateway-event-occasionally-error-when-execute-project-libary-script-nameerror-name-is-not-defined/92012/3 "2024-06-18T12:36:08Z")

</div>

No, this project isn't frequently edited, and some errors occur at midnight when no one is actively editing the project.  
While this project does inherit from another, but the running script is actually present within the current project itself.  
I will report to IA support , thanks.

---

<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:** [June 18, 2024, 12:38pm UTC](https://forum.inductiveautomation.com/t/gateway-event-occasionally-error-when-execute-project-libary-script-nameerror-name-is-not-defined/92012/4 "2024-06-18T12:38:47Z")

</div>

> [@Lina\_Su](#):
>
> While this project does inherit from another, but the running script is actually present within the current project itself.

Doesn't matter. Edits on the other will cause the current project's scripts to restart.

---

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [June 18, 2024, 12:40pm UTC](https://forum.inductiveautomation.com/t/gateway-event-occasionally-error-when-execute-project-libary-script-nameerror-name-is-not-defined/92012/5 "2024-06-18T12:40:37Z")

</div>

The inherited project is not frequently edited either, still thanks for bring this up , I keep this in mind.

---

<div class="post-metadata">

**Author:** ![Brandon\_Peterson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brandon_peterson/32/32960_2.png) [@Brandon\_Peterson](https://forum.inductiveautomation.com/u/Brandon_Peterson)\
**Post date:** [June 18, 2024, 1:10pm UTC](https://forum.inductiveautomation.com/t/gateway-event-occasionally-error-when-execute-project-libary-script-nameerror-name-is-not-defined/92012/6 "2024-06-18T13:10:32Z")

</div>

I've had a problem like this before. I'm not sure if it's the same thing here, but it would be worth a check.

> [@Project Library Script Scope Issues in Gateway Scheduled Script](https://forum.inductiveautomation.com/t/project-library-script-scope-issues-in-gateway-scheduled-script/76137/2):
>
> That usually means someone edited that script and introduced a syntax error. Or some other error is occurring at the top level, prevent it from being imported. Look in your gateway logs. Try making a trivial change in that script, and saving the project. If there's a problem with its automatic import, it should show up in the gateway log shortly after. (Adding or removing a blank line at the bottom is a pretty safe trivial change.)

If you can safely call this script from the Script Console, then your script is compiling and this isn't the solution to your issue.

If it is a compile error, a common culprit is spacing. It doesn't matter if you use tabs or spaces, so long as you're consistent. I'd recommend turning on whitespace characters when looking through the script to find invisible errors. To see them, right-click in the script editor to find the setting.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/7/c7377133c7bc713ed203ebaf9f2483ecdb79811e.png)

Once it's selected, you'll see tabs as arrows and spaces as tiny dots:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/0/203e1270de53fa8b9a335b0dd0044b4177ef8d55.png)

This can help you find errors that would otherwise be easy to miss:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/8/68f3b55302c6071739edf27f83e0c269e4e37ed1.png)

---

<div class="post-metadata">

**Author:** ![Lina\_Su](https://avatars.discourse-cdn.com/v4/letter/l/7ba0ec/32.png) [@Lina\_Su](https://forum.inductiveautomation.com/u/Lina_Su)\
**Post date:** [July 24, 2024, 2:40pm UTC](https://forum.inductiveautomation.com/t/gateway-event-occasionally-error-when-execute-project-libary-script-nameerror-name-is-not-defined/92012/7 "2024-07-24T14:40:05Z")

</div>

I upgraded my Ignition to 8.1.42 recommended by IG support and issue resolved.
