# Tag value changed script "currentValue" always true when used in if statement?

**URL:** <https://forum.inductiveautomation.com/t/tag-value-changed-script-currentvalue-always-true-when-used-in-if-statement/90898>\
**Category:** Ignition\
**Created:** [May 24, 2024, 6:09pm UTC](https://forum.inductiveautomation.com/t/tag-value-changed-script-currentvalue-always-true-when-used-in-if-statement/90898 "2024-05-24T18:09:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joshua\_Graham](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Joshua\_Graham](https://forum.inductiveautomation.com/u/Joshua_Graham)\
**Post date:** [May 24, 2024, 6:09pm UTC](https://forum.inductiveautomation.com/t/tag-value-changed-script-currentvalue-always-true-when-used-in-if-statement/90898/1 "2024-05-24T18:09:29Z")

</div>

I've had to use the "System.tag.read" to get the value of the tag within the "Value Changed" script because "currentValue" is inconsistent. When I use it with an if statement it always thinks it's true, when I use it with "System.tag.write" it writes the value I expect.

```python
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	#cv = system.tag.read("[default]Oscillators/%s" % (machine)).value
	cv = currentValue
	if cv 
		system.tag.write("[default]New Tag", 1)
	else:
		system.tag.write("[default]New Tag", 0)

```

Whether the value of the tag is true or false, it still writes 1 to the new tag.

If it's done like this though, it works as expected so New Tag becomes true or false depending on the value of the tag changing.

```python
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	cv = system.tag.read("[default]Oscillators/%s" % (machine)).value
	#cv = currentValue
	if cv 
		system.tag.write("[default]New Tag", 1)
	else:
		system.tag.write("[default]New Tag", 0)

```

But somehow this also works.

```python
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	system.tag.write("[default]New Tag", currentValue)

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 24, 2024, 6:11pm UTC](https://forum.inductiveautomation.com/t/tag-value-changed-script-currentvalue-always-true-when-used-in-if-statement/90898/2 "2024-05-24T18:11:28Z")

</div>

Try `cv = currentValue.value`

currentValue and previousValue are Qualified Values, similar to what you get from a tag read.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [May 24, 2024, 6:14pm UTC](https://forum.inductiveautomation.com/t/tag-value-changed-script-currentvalue-always-true-when-used-in-if-statement/90898/3 "2024-05-24T18:14:51Z")

</div>

This video might be helpful on understanding qualitied values and what is returned.

> **[Reading and Writing Tags Video at Inductive University](https://inductiveuniversity.com/video/reading-and-writing-tags/7.9)**
>
> Learn how to read from and write to Tags from a script.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 24, 2024, 6:26pm UTC](https://forum.inductiveautomation.com/t/tag-value-changed-script-currentvalue-always-true-when-used-in-if-statement/90898/4 "2024-05-24T18:26:02Z")

</div>

> [@Joshua\_Graham](#):
>
> But somehow this also works.

Because, `system.tag.write()` and it's replacments `system.tag.writeBlocking()` and `system.tag.writeAsync()` (which you should be using) accept a qualified value. So in the background the function correctly breaks out the objects value for the write.
