# Store Integer Values from one OPC tag to an Array tag

**URL:** <https://forum.inductiveautomation.com/t/store-integer-values-from-one-opc-tag-to-an-array-tag/75602>\
**Category:** Ignition\
**Created:** [June 27, 2023, 6:16pm UTC](https://forum.inductiveautomation.com/t/store-integer-values-from-one-opc-tag-to-an-array-tag/75602 "2023-06-27T18:16:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_McCarville](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@Kevin\_McCarville](https://forum.inductiveautomation.com/u/Kevin_McCarville)\
**Post date:** [June 27, 2023, 6:16pm UTC](https://forum.inductiveautomation.com/t/store-integer-values-from-one-opc-tag-to-an-array-tag/75602/1 "2023-06-27T18:16:37Z")

</div>

I have an OPC tag that updates with new Integer values. I need to take the previous 10 values and store them into an array tag in ignition so that I can calculate the running average of the previous 10 values. The reason why I can't just use historian tags is because I need this running average to report in Ignition.

Thanks

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 27, 2023, 7:23pm UTC](https://forum.inductiveautomation.com/t/store-integer-values-from-one-opc-tag-to-an-array-tag/75602/2 "2023-06-27T19:23:27Z")

</div>

My first suggestion:

- Create three tags:
  - the integer array tag with length of ten.
  - an array pointer.
  - a tag to hold the average value.

- Create a gateway onChange event script. Note that this needs to monitor something in your process that changes every time if there is a likelihood of two consecutive readings having the same value.
- Have the even'ts script write to the array using the pointer as the array offset.
- Add 1 to the pointer using modulo arithmatic. e.g. `pointer = (pointer + 1) % 10` and write that back to the pointer tag.
- Calculate the average and write it out to the average tag.

If you have many of these operations to do then select the tags as a group, right-click and select _Create Data Type from Selected_. This will create a UDT and you can use that to create multiple copies.

---

<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 27, 2023, 7:37pm UTC](https://forum.inductiveautomation.com/t/store-integer-values-from-one-opc-tag-to-an-array-tag/75602/3 "2023-06-27T19:37:21Z")

</div>

Sounds like the `recorder()` function from my free [Simulation Aids](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids) module.

---

<div class="post-metadata">

**Author:** ![Kevin\_McCarville](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@Kevin\_McCarville](https://forum.inductiveautomation.com/u/Kevin_McCarville)\
**Post date:** [June 27, 2023, 9:01pm UTC](https://forum.inductiveautomation.com/t/store-integer-values-from-one-opc-tag-to-an-array-tag/75602/4 "2023-06-27T21:01:58Z")

</div>

> [@Kevin\_McCarville](#):
>
> Thanks

Thank you for the reply. This makes sense. Just one question, where can I define the initial value for "pointer"? If I define pointer = 0 in the change script, then the value with never increment as it just goes back to 0 whenever the change script is triggered.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 27, 2023, 9:10pm UTC](https://forum.inductiveautomation.com/t/store-integer-values-from-one-opc-tag-to-an-array-tag/75602/5 "2023-06-27T21:10:22Z")

</div>

> [@Kevin\_McCarville](#):
>
> where can I define the initial value for "pointer"?

When you create a memory tag you have the option to set the (initial) value in the tag editor or directly in the tag browser.
