# Timer Script - Gateway Events

**URL:** <https://forum.inductiveautomation.com/t/timer-script-gateway-events/39155>\
**Category:** Ignition\
**Tags:** scripting, ignition80\
**Created:** [September 29, 2020, 1:05am UTC](https://forum.inductiveautomation.com/t/timer-script-gateway-events/39155 "2020-09-29T01:05:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![panozzosebastian02](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@panozzosebastian02](https://forum.inductiveautomation.com/u/panozzosebastian02)\
**Post date:** [September 29, 2020, 1:05am UTC](https://forum.inductiveautomation.com/t/timer-script-gateway-events/39155/1 "2020-09-29T01:05:54Z")

</div>

I have an issue when trying to make an script for updating a tag value every second, it just don´t obey the time configuration.  
Here is the code:  
s=system.tag.read(“REGISTRO”).value  
if s:  
A=system.tag.read(“SEG”).value  
B=system.tag.read(“MIN”).value  
C=system.tag.read(“HOR”).value  
if A==60:  
A=0  
B=B+1  
else:  
A=A+1  
if B==60:  
B=0  
C=C+1  
system.tag.write(“SEG”,A)  
system.tag.write(“MIN”,B)  
system.tag.write(“HOR”,C)  
else:  
system.tag.write(“SEG”,0)  
system.tag.write(“MIN”,0)  
system.tag.write(“HOR”,0)  
And the script configuration is:  
Delay(ms): 1,000  
Enabled: True  
Delay Type: Fixed Delay  
Threading: Shared

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 29, 2020, 12:16pm UTC](https://forum.inductiveautomation.com/t/timer-script-gateway-events/39155/2 "2020-09-29T12:16:17Z")

</div>

Please edit your post and wrap your code with 3 back ticks ``` at the start and end so that formatting is maintained.

Also, timing is not guaranteed especially not when run in the shared thread . But try using fixed period and run it in a dedicated thread

“A Fixed Delay timer script (the default) waits for the given Delay between each script invocation. This means that the script’s rate will actually be the delay plus the amount of time it takes to execute the script”

Also you should optimise your read and writes by bulk reading and writing all tags at once

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 29, 2020, 12:28pm UTC](https://forum.inductiveautomation.com/t/timer-script-gateway-events/39155/3 "2020-09-29T12:28:14Z")

</div>

What is the value of “REGISTRO”? It may make more sense to do this as a tag event instead.

---

<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:** [September 29, 2020, 1:19pm UTC](https://forum.inductiveautomation.com/t/timer-script-gateway-events/39155/4 "2020-09-29T13:19:10Z")

</div>

Also would be better to not make your own timer. Save a timestamp on changes of REGISTRO and do math on the time deltas. Ignition’s timer events have no precision guarantees.
