I have a few different ideas on how to handle this, but not sure what the BEST way to go about it would be.
I have a script that I really want to run only 60 seconds, but it doesn’t need to run if nobody is looking at screen X.
I could of course put an if statement in the gateway timer script that checks for a flag that the window is open somewhere, but I want the script to run right away when the screen is first opened. I don’t want the user to wait for the 60s timer to run again before getting fresh data. Additionally, if another client opens the screen it shouldn’t cause a new run, just continue running every 60s.
I’m sure I’m missing something obvious here, thanks!
I often use a specially created trigger tag for this purpose.
Just create a memory tag (a boolean is enough), and use a “Value Changed” script on that tag (or a gateway tag changed event).
When you have this, you can toggle the tag from anywhere, and execute the script.
- You can trigger it when the window is opened
- You can add a gateway timer to toggle it every minute if you want it to be independent from the open clients
- You can add a gui timer that toggles the tag every minute, perhaps check the timestamp to ensure two clients don’t cause double the toggle speed
- You can offer a “refresh” button in the GUI to force executing the script
1 Like
ah the gateway timer to toggle the trigger every minute was what i was missing. duh! thanks!
You could also use a Boolean expression tag (e.g. customTimer) with an expression like:
getMinute(now()) % 2 = 0
With a driven scan class that runs whenever the value of customTimer changes, you can change the timing by editing the expression.
1 Like