I am working on a Perspective project on Gateway 8.0.10.
I have a script in the Project Library that is a very simple state machine: If A is true, go to B. If A and F are true, go to C (and so forth). I want to trigger running the script (which checks tag values, then updates the state) on a tag change, since the script only needs to be checked when a tag changes.
Since tag ‘Value Changed’ event scripts can’t call scripts in the Project Library, is there an easy way to use this event to run my script in the Project Library?
In a word, yes, but it’s because the terminology here is a little overloaded. Since changing the gateway scripting project isn’t an option, you need to use a different paradigm. Rather than tag event scripts - what you’re describing, where you specify a valueChanged() script on a particular tag, I’m suggesting using tag change scripts - a project scoped resource (that still executes on the gateway) that has full access to your project script library.
“Tag change” vs “tag event” scripts are obviously pretty unfortunate terminology, but it’s what we’ve got.
Maintainability–shared script editing in particular–without disrupting the global scripting project (v8) or all projects (v7.x). Tag events defined in UDTs mitigate the problem somewhat, but then all of the affected tags restart when those are edited. Editing gateway events in a project, along with the associated project scripts, disrupts only that project. Tags don’t restart at all.
I’m curious so let’s say we have a UDT with 10 tags each with event scripts. Then you have 10 instances of that UDT.
Do you create your script in a library, and then have to set a tag event for all 100 of those tags? Or is there a way to have it apply to everything like when you put it on the UDT. Like having the UDT Tag script just call the library function, so that when you adjust the library function it doesn’t restart the tags?
Can you do a project level tag even script for a UDT definition?
Gateway tag change events allow you to list the tags that should trigger them. Can be hundreds or thousands. Which tag is involved in each event is passed in. Changing the list of subscribed tags when adding/removing/changing behavior is a project save, not a tag restart. The project does not have to the global scripting project. The event script can (and should) call project script functions in that same project.