Tag event scripting - only when tag value changes

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:

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:

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!

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

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?

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.

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