# Scope for methods defined in Gateway Event Script

**URL:** <https://forum.inductiveautomation.com/t/scope-for-methods-defined-in-gateway-event-script/36701>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [July 14, 2020, 9:15pm UTC](https://forum.inductiveautomation.com/t/scope-for-methods-defined-in-gateway-event-script/36701 "2020-07-14T21:15:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [July 14, 2020, 9:15pm UTC](https://forum.inductiveautomation.com/t/scope-for-methods-defined-in-gateway-event-script/36701/1 "2020-07-14T21:15:47Z")

</div>

Ignition 8.0.10

I’ve put the following code in a gateway timer script and in the action performed event handler of a vision client button. In the vision button it performs exactly how I expect it would, printing to the console. In the gateway script I expected to see a print out in the wrapper.log file, but I didn’t. I instead got

```auto
NameError: global name 'testVar' is not defined

```

I must be misunderstanding some nuance of scoping in gateway event scripts. Could someone point me in the right direction toward understanding this?

```auto
testVar = 'Test'
def test_function():
	print testVar
test_function()

```

---

<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:** [July 14, 2020, 9:18pm UTC](https://forum.inductiveautomation.com/t/scope-for-methods-defined-in-gateway-event-script/36701/2 "2020-07-14T21:18:22Z")

</div>

Yup. Legacy scoping for ancient backwards compatibility. IA missed an opportunity to fix this with v8. /:

You’ll want to place your code in a regular script module and call it from the event, passing the event variable(s) as function arguments.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [July 14, 2020, 9:26pm UTC](https://forum.inductiveautomation.com/t/scope-for-methods-defined-in-gateway-event-script/36701/3 "2020-07-14T21:26:23Z")

</div>

Since a gateway event script is associated with a project, can a project level script module be used or does it require a gateway accessible script module?

---

<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:** [July 14, 2020, 9:28pm UTC](https://forum.inductiveautomation.com/t/scope-for-methods-defined-in-gateway-event-script/36701/4 "2020-07-14T21:28:14Z")

</div>

Project scripts are fine. That’s one of the reasons I prefer (and recommend) gateway tag change events (in the project) over Value/Quality/Timestamp tag events (not in a project).

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [July 14, 2020, 9:31pm UTC](https://forum.inductiveautomation.com/t/scope-for-methods-defined-in-gateway-event-script/36701/5 "2020-07-14T21:31:41Z")

</div>

Thanks for help. It really through me for awhile.
