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

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:

Best Regards.

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:

[project.]someScript.someFunction(event)

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

1 Like