You can help by commenting or suggesting your edit directly into the transcript. We'll review any changes before posting them. All comments are completely anonymous. For any comments that need a reply, consider emailing firstname.lastname@example.org.
We are experiencing playback issues from our video hosting provider. Please check back shortly.
4:53Gateway vs. Client Event Scripts
5:29Tag Change Scripts
Take topic challenge
Tag Change Scripts
Learn how to write scripts that fire when a Tag changes on the Client or the Gateway.
Video recorded using: Ignition 7.7
Transcript(open in window)
[00:00] In this lesson we're going to learn about tag change scripts. First we're going to look at client scopes tag change scripts. So in this example project I have two windows. I have the main window that has a check box. And this check box simply writes to this OpenTheWindow tag. And what we want to do is we want to open up this popup window when this tag changes. And so the best way to do this is with a client scoped tag change script. So we go under Client Event Scripts and choose tag change. And you can have lots of tag, client tag change scripts. So we need to add one here. And we can give it a name. Let's call it Window Opener. And we want to trigger this script, let's say, only when the value changes. And now we need to add all of the tags that are going to trigger this script, and you can have multiple tags in this list. Just one tag per line and each, when any of those tags change it will trigger this script to run. Now when this script runs you're going to get three variables given to you. One of them is event, which is a tag change event object, and the most important part of that is that it has the tag path on it. So in the case where you've configured a tag change script that can be triggered for multiple paths, you can check which tag has changed using the event.tagPath property. There's also the initialChange flag. So there's a variable here called initialChange. Like that, initialChange. It's a zero or a one based on whether or not this script was triggered by subscribing to the tag or not. So whenever you first start up a system and it subscribes to all the tags it gets an initialChange event saying, well, the tag didn't really just change right now, but you just subscribed so we figured we might want to let you know what the initial value is. And so sometimes that's really useful for a tag change script and sometimes it's not. And so, if you want to consume that initial value you don't have to worry about this initialChange. But if you want to ignore that initial value you would want to not run your script if the initial change flag is set to true. And lastly we have the newValue variable. New value is a qualified value, so it self contains a value, quality, and timestamp. And this tells you what value the tag changed to. And so in our case newValue is really what we care about, because if we only want to open our popup window when this Boolean has become true. So we can just do something like this. If newValue.value, and that's a Boolean so that's all we need. So if that value's true then we want to run system.nav.openWindow, and we want to open up the Popup window. And let's just center it, too. Okay. So let's go ahead and save this tag change script and launch a client. And we can watch our tag change script in action. So we're going to go ahead and write a true value to this tag. And tada, our popup window is opened. And if we go into the client diagnostics and the console we can see the result of those printouts that we printed out. So here's the, this is the initial change that the script got. So when we very first started up the client by subscribing to this tag we got one of our events fired. And so our script ran. You can see initial changes one and the value is false. And because we were checking the value for opening up the popup it didn't open up the popup at that point. And then here's the second time that that script ran, in this case initial change is zero, and the value's true, and that's when we opened our popup window. Gateway Event Scripts work in much the same way that Client Event Scripts work in. You can see the UI here is exactly the same. Again, it's just important to remember what I was talking about with the initial change because if you have a whole bunch of gateway tag change scripts don't be surprised with the idea that all of them are going to run when the system starts up because they've gotten that initial change. So if that's a problem for the logic that you're executing in your gateway tag change script, you can just protect against that with the initialChange flag.