# Derived Tag Incrementing Memory Tag Value

**URL:** <https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023>\
**Category:** Ignition\
**Created:** [November 16, 2017, 3:57pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023 "2017-11-16T15:57:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahardin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahardin/32/66398_2.png) [@ahardin](https://forum.inductiveautomation.com/u/ahardin)\
**Post date:** [November 16, 2017, 3:57pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/1 "2017-11-16T15:57:05Z")

</div>

Hi all,

I’m new to Ignition so hoping to get some assistance with something that seems like it should be possible. I’m experimenting with a Derived Tag. I would like to compare the value of two tags, if they do not meet my requirements I would like to increment the value of a memory tag.

Could someone point me in the right direction?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [November 16, 2017, 5:03pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/2 "2017-11-16T17:03:55Z")

</div>

You can use a [gateway timer script](https://docs.inductiveautomation.com/display/DOC79/Timer+Scripts).  
In that script, compare the values of the two tags using [system.tag.read](https://docs.inductiveautomation.com/display/DOC79/system.tag.read) and if they are not within your requirments, increment your memory tag using [system.tag.write](https://docs.inductiveautomation.com/display/DOC79/system.tag.write).

---

<div class="post-metadata">

**Author:** ![ahardin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahardin/32/66398_2.png) [@ahardin](https://forum.inductiveautomation.com/u/ahardin)\
**Post date:** [November 16, 2017, 6:21pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/3 "2017-11-16T18:21:18Z")

</div>

Thanks for the reply! I had tried using a Tag Event Script but I it wouldn’t update the tag. Checking the log, it would give a valueChanged NameError: and say the tag doesn’t exist.

I created an expression tag and it would update itself correctly, but this is where I had the Tag Event Script and it didn’t work.

I’ll try the gate timer script to see if I can make headway with hit. I liked the idea of the tag though.

---

<div class="post-metadata">

**Author:** ![ahardin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahardin/32/66398_2.png) [@ahardin](https://forum.inductiveautomation.com/u/ahardin)\
**Post date:** [November 16, 2017, 6:53pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/4 "2017-11-16T18:53:01Z")

</div>

This isn’t what I’m wanting, but its an example of it not working.

If the tag Counter has a timestamp older than tag Current\_Sheet, I would like to have the value to match the tag Counter.

var0 = system.tag.read(“Counter”).value  
var1 = system.tag.read(“Counter”).timestamp  
var2 = system.tag.read(“Current\_Sheet”).timestamp  
if var1 \> var2:  
system.tag.write(“Current\_Sheet”, var0)

---

<div class="post-metadata">

**Author:** ![Kevin.Collins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.collins/32/13497_2.png) [@Kevin.Collins](https://forum.inductiveautomation.com/u/Kevin.Collins)\
**Post date:** [November 16, 2017, 7:01pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/5 "2017-11-16T19:01:11Z")

</div>

Make sure that you specify the provider when targeting tags from the gateway scope, e.g. `[default]MyTag` instead of `MyTag`.

Hope this helps…

---

<div class="post-metadata">

**Author:** ![ahardin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahardin/32/66398_2.png) [@ahardin](https://forum.inductiveautomation.com/u/ahardin)\
**Post date:** [November 16, 2017, 7:26pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/6 "2017-11-16T19:26:51Z")

</div>

Thank you, I’ll try that now!

---

<div class="post-metadata">

**Author:** ![ahardin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahardin/32/66398_2.png) [@ahardin](https://forum.inductiveautomation.com/u/ahardin)\
**Post date:** [November 16, 2017, 8:22pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/7 "2017-11-16T20:22:57Z")

</div>

From the Script Console I can enter the following and it works but not from a Gateway Tag Script. I tried the square brackets but it wouldn’t work in either window.

var1 = system.tag.read(‘SizingSaw/Counter’)  
var2 = system.tag.read(‘SizingSaw/Current\_Sheet’)

if var1 \<\> var2:  
system.tag.write(‘SizingSaw/Current\_Sheet.value’, var1.value)

---

<div class="post-metadata">

**Author:** ![ahardin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahardin/32/66398_2.png) [@ahardin](https://forum.inductiveautomation.com/u/ahardin)\
**Post date:** [November 16, 2017, 8:30pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/8 "2017-11-16T20:30:07Z")

</div>

Finally, I was able to get it to work using a Tag Event Script. I didn’t change anything so not sure what’s wrong but I’m happy.

Thanks!!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 16, 2017, 9:31pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/9 "2017-11-16T21:31:19Z")

</div>

Gateway-scoped scripts need fully-qualified paths; they don’t know what realtime tag provider to execute reads/writes against. So `system.tag.read("SizingSaw/Counter")` would become `system.tag.read("[default]SizingSaw/Counter")` in a gateway script.

---

<div class="post-metadata">

**Author:** ![diegui-gr](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@diegui-gr](https://forum.inductiveautomation.com/u/diegui-gr)\
**Post date:** [November 21, 2018, 7:11pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/10 "2018-11-21T19:11:52Z")

</div>

Hola que tal puedes, pasar el codigo de la solucion.  
Gracias

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 11, 2021, 3:04pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/11 "2021-03-11T15:04:33Z")

</div>

I hope it is okay that I am bringing back a question from 2017

I am using version 8.1 while trying to count an event. I can assign values to the tag. I can’t seem to get it to increment itself though.

system.tag.write("[.]New Tag", “[.]New Tag”+1)

did not work inside a valuechanged script in a tag

and

tempvariable=("[.]New Tag"+1)  
system.tag.write("[.]New Tag", tempvariable)

This did not work

however,

for some reason

tempvariable=(7)  
system.tag.write("[.]New Tag", tempvariable)

This one worked, and assigned the value to 7

---

<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:** [March 11, 2021, 3:07pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/12 "2021-03-11T15:07:51Z")

</div>

> [@zacharyw.larson](#):
>
> I am using version 8.1 while trying to count an event. I can assign values to the tag. I can’t seem to get it to increment itself though.
> 
> system.tag.write("[.]New Tag", “[.]New Tag”+1)

This isn't an expression, that syntax for reading the value doesn't do anything. You're trying to write a String value with '1' concatenated to the end of it.

If you want to increment the value of a tag read the value first using system.tag.readBlocking before you increment and write it again.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 11, 2021, 3:11pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/13 "2021-03-11T15:11:25Z")

</div>

Can you give me an example line of code that will write a tag to value of itself plus 1?

The tag event scripting tutorial used strings.

---

<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:** [March 11, 2021, 3:14pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/14 "2021-03-11T15:14:02Z")

</div>

I put this in a button’s actionPerformed event:

```auto
qv = system.tag.readBlocking(["Test"])[0]

new_v = qv.value + 1

system.tag.writeBlocking(["Test"], [new_v])

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 11, 2021, 3:20pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/15 "2021-03-11T15:20:15Z")

</div>

qv = system.tag.readBlocking([“Test”])[0]

new\_v = qv.value + 1

system.tag.writeBlocking([“Test”], [new\_v])

When I look at this:  
I am understanding that the qv variable begins to exist in the first line.  
The system.tag.readBlocking is reading the value of the tag called Test.  
The brackets that are square differentiate the value of the tag vs it being a string?  
I am totally confused by the  
[0]  
on the end of the first line.

Second line, why is .value used?  
Would  
qv+1  
not work?

I don’t have questions about the last line.

Thanks for helping me.  
I program in a few languages, and it seems to be hindering me haha

---

<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:** [March 11, 2021, 3:22pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/16 "2021-03-11T15:22:06Z")

</div>

> [@zacharyw.larson](#):
>
> The brackets that are square differentiate the value of the tag vs it being a string?  
> I am totally confused by the  
> [0]  
> on the end of the first line.

Because `readBlocking` accepts a list of tag paths and returns a list of QualifiedValues, corresponding in length and position with those tag paths.

> [@zacharyw.larson](#):
>
> Second line, why is .value used?

This is because of what I mentioned above about it returning a list of QualifiedValue, which is an object with value, timestamp, and quality components. You need to get the value out of it to actually increment.

[https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking)  
[https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking)

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 11, 2021, 6:32pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/17 "2021-03-11T18:32:49Z")

</div>

temp = system.tag.readBlocking(["[.]New Tag"],[0])  
tempvariable=temp.value+1  
system.tag.writeBlocking(["[.]New Tag"],[tempvariable],[0])  
system.tag.writeBlocking(["[.]New Tag2"],6)

I have written this.  
It does not change the values of either New Tag or New Tag2.  
When I designate the tag, I click on the tag icon, then find the tag to insert.  
[.]  
is automatically written as part of the tag.

I noticed your code did not have [.]  
I noticed in other versions, code reads like [Default]“Tag” rather than [.]“Tag”  
Is that part wrong in my code?

I looked at both links, and tried a few ways to fix my code. I am still trying things till I hear back too.  
Thank you for helping me. If there is any training I might have missed, I will review it.  
I am watching the videos too to see if I missed it.

temp = system.tag.readBlocking(["[.]New Tag.value"],[0])  
tempvariable=temp.value+1  
system.tag.writeBlocking(["[.]New Tag.value"],[tempvariable],[0])  
system.tag.writeBlocking(["[.]New Tag2.value"],6)

This attempt also did not work, if it helps to spot the part I am misunderstanding.

Actually just found out I can spot errors in the diagnostic tab when I doubleclick the tag.

---

<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:** [March 11, 2021, 7:17pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/18 "2021-03-11T19:17:44Z")

</div>

> [@zacharyw.larson](#):
>
> temp = system.tag.readBlocking(["[.]New Tag"],[0])  
> tempvariable=temp.value+1  
> system.tag.writeBlocking(["[.]New Tag"],[tempvariable],[0])  
> system.tag.writeBlocking(["[.]New Tag2"],6)

Should be

```auto
temp = system.tag.readBlocking(["[.]New Tag"])[0]
tempvariable = temp.value + 1
system.tag.writeBlocking(["[.]New Tag","[.]New Tag2"],[tempvariable,6])

```

The [.] is shorthand that means the path is Realative to the folder of the Tag that is being bound.

[https://docs.inductiveautomation.com/display/DOC81/Tag+Paths](https://docs.inductiveautomation.com/display/DOC81/Tag+Paths)

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 11, 2021, 7:20pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/19 "2021-03-11T19:20:19Z")

</div>

> [@lrose](#):
>
> temp = system.tag.readBlocking("[.]New Tag") tempvariable = temp.value + 1 system.tag.writeBlocking(["[.]New Tag","[.]New Tag2"],[tempvariable,6])

That did not work for me either.

---

<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:** [March 11, 2021, 7:20pm UTC](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023/20 "2021-03-11T19:20:41Z")

</div>

Sorry, had a typo, the code has been edited.

[Next page](https://forum.inductiveautomation.com/t/derived-tag-incrementing-memory-tag-value/16023.md?page=2)
