# Script on tag value changed

**URL:** <https://forum.inductiveautomation.com/t/script-on-tag-value-changed/75150>\
**Category:** Ignition\
**Created:** [June 16, 2023, 3:19pm UTC](https://forum.inductiveautomation.com/t/script-on-tag-value-changed/75150 "2023-06-16T15:19:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [June 16, 2023, 3:19pm UTC](https://forum.inductiveautomation.com/t/script-on-tag-value-changed/75150/1 "2023-06-16T15:19:32Z")

</div>

does it make a difference if the tag reference in the below script is in the same folder or in a different folder?  
**same folder**  
if currentValue.value == 12 or currentValue.value == 20 or currentValue.value == 4:  
crank\_max = system.tag.readBlocking(["[.]Crank\_max"])[0].value  
system.tag.writeBlocking(["[.]P8\_C\_Target"], [crank\_max])

**different folder**  
if currentValue.value == 12 or currentValue.value == 20 or currentValue.value == 4:  
main\_max = system.tag.readBlocking(["[.]../IC\_Main\_Hr/Main\_max"])[0].value  
system.tag.writeBlocking(["[.]P8\_M\_Target"], [main\_max])

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 16, 2023, 5:00pm UTC](https://forum.inductiveautomation.com/t/script-on-tag-value-changed/75150/3 "2023-06-16T17:00:24Z")

</div>

Not particularly, no.

---

<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:** [June 16, 2023, 5:04pm UTC](https://forum.inductiveautomation.com/t/script-on-tag-value-changed/75150/4 "2023-06-16T17:04:17Z")

</div>

It makes little to no difference as the tag path will need to be resolved anyway, perhaps that code is short-circuiting, I don't actually know, but I wouldn't think that it will gain you much.

However, you should definitely be using `system.tag.writeAsync()` here, particuarly if your tags are changing often or if you have many of this type of thing in your tags.

```auto
if currentValue.value in (12,20,4):
    crankMax = system.tag.readBlocking(['[.]Crank_Max'])[0].value
    system.tag.writeAsync(['[.]P8_C_Target'],[crank_max]) 

```

Even better would be to make the `'P8_C_Target'` and `'P8_M_Target'` tags expression or driven tags.

[https://docs.inductiveautomation.com/display/DOC81/Types+of+Tags](https://docs.inductiveautomation.com/display/DOC81/Types+of+Tags)
