Linking Tags Using a Gateway Tag Change Script

Using a gateway tag change script, I am trying to update a tag's value (we'll call this tag_2) when another tag changes (tag_1). However, I only want to update tag_2's value when the value of tag_1 is an integer between 1 and 8. Any suggestions?

  1. Don't import system
  2. Why cast a value, and then immediately check if it is an instance of the type you just cast it to? If you're trying to verify that the casting was successful, then a try, except would be more appropriate.

If you want the lane_number tag to be an integer, then make that tag's type an integer, then there is no need to cast it. Don't store values as strings when you want to use them as a different type.

This code should simply be:

if 0 < newValue.value <= 8:
    system.tag.writeBlocking(["path to tag"],[newValue.value])
3 Likes