# Issue with If statement in Tag Change Script

**URL:** <https://forum.inductiveautomation.com/t/issue-with-if-statement-in-tag-change-script/96676>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [October 1, 2024, 8:23pm UTC](https://forum.inductiveautomation.com/t/issue-with-if-statement-in-tag-change-script/96676 "2024-10-01T20:23:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Karee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew_karee/32/63956_2.png) [@Matthew\_Karee](https://forum.inductiveautomation.com/u/Matthew_Karee)\
**Post date:** [October 1, 2024, 8:23pm UTC](https://forum.inductiveautomation.com/t/issue-with-if-statement-in-tag-change-script/96676/1 "2024-10-01T20:23:38Z")

</div>

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:

```python
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:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/2/528979f0f5b02ca9027480ecad0335282d4ca425.png)

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'`

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 1, 2024, 8:26pm UTC](https://forum.inductiveautomation.com/t/issue-with-if-statement-in-tag-change-script/96676/2 "2024-10-01T20:26:06Z")

</div>

> [@Matthew\_Karee](#):
>
> ```python
> dl_ID = system.tag.readBlocking('[edge]CLICK_values/Line1/DL_ID')
> 
> ```

This should be

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

```

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [October 1, 2024, 8:50pm UTC](https://forum.inductiveautomation.com/t/issue-with-if-statement-in-tag-change-script/96676/3 "2024-10-01T20:50:39Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 2, 2024, 5:34pm UTC](https://forum.inductiveautomation.com/t/issue-with-if-statement-in-tag-change-script/96676/4 "2024-10-02T17:34:47Z")

</div>

> [@michael.flagler](#):
>
> newValue.getValue()

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