# Tag event scripting - only when tag value changes

**URL:** <https://forum.inductiveautomation.com/t/tag-event-scripting-only-when-tag-value-changes/32782>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [March 3, 2020, 7:49pm UTC](https://forum.inductiveautomation.com/t/tag-event-scripting-only-when-tag-value-changes/32782 "2020-03-03T19:49:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard.d.white](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@richard.d.white](https://forum.inductiveautomation.com/u/richard.d.white)\
**Post date:** [March 3, 2020, 7:49pm UTC](https://forum.inductiveautomation.com/t/tag-event-scripting-only-when-tag-value-changes/32782/1 "2020-03-03T19:49:51Z")

</div>

Hello - I have a basic question which I’m sure has an easy solution (but cannot figure out):

I am trying to use ignition to totalize incoming values on a particular tag. Changes to the value of the tag are all I need (not absolute values), so scripting should be straightforward:

```auto
if currentValue.value !=previousValue.value:			
    oldvalue = system.tag.read("[.]Totalizer").value
    system.tag.write("[.]Totalizer",oldvalue+1)

```

The problem is that when there is a gateway reset or update, I’m also registering a bump in totalizer value. One of my tags even registered three changes during the reset event. I should also mention that I ran the following code and STILL saw the totalizer updating in response to the gateway reset instead of the tag itself actually changing value:

```auto
if (initialChange==0) and (currentValue.value !=previousValue.value):			
    oldvalue = system.tag.read("[.]Totalizer").value
    system.tag.write("[.]Totalizer",oldvalue+1)

```

Can anyone suggest what I may be doing wrong here? Thanks!

---

<div class="post-metadata">

**Author:** ![richard.d.white](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@richard.d.white](https://forum.inductiveautomation.com/u/richard.d.white)\
**Post date:** [March 3, 2020, 7:50pm UTC](https://forum.inductiveautomation.com/t/tag-event-scripting-only-when-tag-value-changes/32782/2 "2020-03-03T19:50:34Z")

</div>

(I just wanted to clarify that there IS indentation under the “if” line…!)

---

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [March 3, 2020, 8:04pm UTC](https://forum.inductiveautomation.com/t/tag-event-scripting-only-when-tag-value-changes/32782/3 "2020-03-03T20:04:43Z")

</div>

I think what you're doing should work as you describe. There were some bugs with initialChange with earlier versions 8 of and I seem to remember some early versions of 7 as well. Which version are you using?

> [@\[BUG - 13165\]Tag Event Script initial Change behavior had changed from 7.9 to 8.0](http://forum.inductiveautomation.com/t/bug-13165-tag-event-script-initial-change-behavior-had-changed-from-7-9-to-8-0/23381/4):
>
> Is there an update on this?

---

<div class="post-metadata">

**Author:** ![richard.d.white](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@richard.d.white](https://forum.inductiveautomation.com/u/richard.d.white)\
**Post date:** [March 4, 2020, 5:12pm UTC](https://forum.inductiveautomation.com/t/tag-event-scripting-only-when-tag-value-changes/32782/4 "2020-03-04T17:12:43Z")

</div>

Thank you for your response. Actually the reason I noticed this was because I was upgrading my build from 8.05 to 8.09 which necessitated a gateway reset. I even reset the gateway myself afterwards to test this again (using gwcmd -r) and sure enough this definitely triggered the tag event. Any other ideas you can provide? Thanks.

---

<div class="post-metadata">

**Author:** ![vasilevdim](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@vasilevdim](https://forum.inductiveautomation.com/u/vasilevdim)\
**Post date:** [August 28, 2020, 3:41pm UTC](https://forum.inductiveautomation.com/t/tag-event-scripting-only-when-tag-value-changes/32782/5 "2020-08-28T15:41:54Z")

</div>

Dear richard.d.white, did you sort out your problem? I have very similar issue with 8.04 version.
