Best Practice for Passing Values Between Scripting Events

My experience with programming has taught me that global variables are a thing to be avoided. Looking to see if this holds true for Ignition as well and what other options are available.

I have a particular set of library scripts where I am using some global variables. A "mousePressed" event gets the client height and width and stores them in globals. Then a "mouseDragged" event, I pull these globals and use them to prevent a user from dragging a popup into no-man's-land. I want to use this script set wherever I have a popup, so I prefer it in the library for ease of use and maintainability.

Anywho, I see a number of issues with this from an extensibility and multiclient access point of view when using global variables.

So getting to my question, is there a clean way to send data between scripting events without using global scripting variables?

I would be more comfortable with client tags, but it looks like scripts in the project library cannot address client tags.

Running Ignition 8.0 for this project.

In Vision, script module global variables, in client scope, are local to the client instance. So are not typically a problem for user clashes.

In Perspective, not so much.

You need state stored somewhere, and script globals can hold state. If you need it to be component or window-specific, look at .putClientProperty and friends.

Not true at all. But since Vision client tags only exist in a client instance, only calls into a project library script from client scope will be able to access them. (Project library scripts have no scope of their own--their scope is the scope of whatever calls them.)


Beautiful answer, thank you.