Issue with If statement in Tag Change Script

This seems prety straightforward but I've been stuck on it for a while so figured I'd post here.

I have the following Tag Change script:

dl_ID = system.tag.readBlocking('[edge]CLICK_values/Line1/DL_ID')

logger = system.util.getLogger('test')
logger.info(str(dl_ID))

if dl_ID > 0: 
	logger.warn(str(dl_ID))

I've omitted the actual intended function of the script, but basically I only want an event to occur if '[edge]CLICK_values/Line1/DL_ID' changes to a non-zero value.

However, when that tag changes to 0 and the script runs, I get the following messages in my log in the gateway, indicating that the script did not obey the if statement as intended:

i.e. the if statement is entered even though dl_ID is not > 0.

All of the involved tags are integers.

Any idea why this would be?

EDIT: Forgot to add that the tag that triggers the script is '[edge]CLICK_values/Line1/DL_ID'

This should be

dl_ID = system.tag.readBlocking('[edge]CLICK_values/Line1/DL_ID')[0].value
2 Likes

One other thing I'll mention is that if the tag that triggers the script is the same one you're using for the readBlocking command, you can get rid of the manual tag read line and use newValue.getValue() instead (assuming this is in a gateway even tag change script by itself without other tags in the tag list.)

2 Likes

I would use the pythonic version:
newValue.value (for gateway tag change events)
Or
currentValue.value (for tag value change events)

4 Likes