# Global Variables are not recognized in functions in "Gateway Events Scripts"

**URL:** <https://forum.inductiveautomation.com/t/global-variables-are-not-recognized-in-functions-in-gateway-events-scripts/31856>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [February 3, 2020, 10:38am UTC](https://forum.inductiveautomation.com/t/global-variables-are-not-recognized-in-functions-in-gateway-events-scripts/31856 "2020-02-03T10:38:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![informatica](https://avatars.discourse-cdn.com/v4/letter/i/3ab097/32.png) [@informatica](https://forum.inductiveautomation.com/u/informatica)\
**Post date:** [February 3, 2020, 10:38am UTC](https://forum.inductiveautomation.com/t/global-variables-are-not-recognized-in-functions-in-gateway-events-scripts/31856/1 "2020-02-03T10:38:24Z")

</div>

Good morning.

I’m using Ignition 8.0.7.

In the “ **Gateway Events Scripts** ”, global variables are not recognized within the **functions** that are declared within the scripts. In the logs you can see this error: “global name ‘NUM\_TURNOS\_DIA’ is not defined”.  
The “ **system** ” package is also not recognized within the functions.  
You have to import it to use it.

For example:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/4/42e2cfe10a82b9c27c351750686587712673be60.png)

Best Regards.

---

<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:** [February 3, 2020, 12:31pm UTC](https://forum.inductiveautomation.com/t/global-variables-are-not-recognized-in-functions-in-gateway-events-scripts/31856/2 "2020-02-03T12:31:15Z")

</div>

This is not really a bug, but it is annoying. Gateway event scripts use legacy python scope rules that prevent any names in the top level event scope from being captured in nested functions’ closures. (Ignition v8 would have been a good choice to drop the backward compatibility…)

If you find you need to define a nested function within a gateway event script, you probably should move the whole thing to a project script module. Then your gateway event becomes a one-liner, something like so:

```auto
[project.]someScript.someFunction(event)

```

Script modules use modern python scoping and will properly form closures for nested function definitions.
