How to execute a script via time or/and via update?

Hi!

I have a tag that changes. I don't know when it's going to change. It's dependedant on a machine.

I have an script that executes whenever the tag changes. However, because the tag could be more than 30 seconds without executing. I would like to execute the script again.

The conditions:

  • The script should execute everytime the tag changes
  • The script should execute if more than 30 seconds before the last script execution have passed

I'm not really sure how to aproach this...

Move the existing script to a function in a project library script. (You should do this anyways, always.) Add to the beginning of the script a write of system.date.now() to a datetime memory tag. Change the tag event to call the project library script.

In the same project library, create a new function that reads the source tag and reads the memory tag. If the memory tag is more than 30s in the past, call the above function.

Make a 1-second timer event call the 2nd function.