# Running Gateway Scripts

**URL:** <https://forum.inductiveautomation.com/t/running-gateway-scripts/32579>\
**Category:** Ignition\
**Created:** [February 25, 2020, 2:15pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts/32579 "2020-02-25T14:15:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![twstevic](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@twstevic](https://forum.inductiveautomation.com/u/twstevic)\
**Post date:** [February 25, 2020, 2:15pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts/32579/1 "2020-02-25T14:15:50Z")

</div>

I am running a very simple gateway script that triggers on the tag change of ‘G\_Timer’.  
The purpose of the script is to simply continuously increment the ‘G\_Counter\_1’ tag value.

```auto
if system.tag.read("[default]G_Timer").value == 1:
	GC1value = system.tag.read("[default]G_Counter_1").value
	GC1value = GC1value + 1
	if GC1value > 9999:
		GC1value = 0
	system.tag.writeBlocking(["[default]G_Counter_1"],[GC1value]) 

```

The part I am having issues with is the’ if GC1value \> 9999:’ evaluation. It simply does not seem to work. I am rather new to Ignition and Python. I did run a Python script with the same ‘if’ statement nesting, and it works as expected. Any thoughts?

---

<div class="post-metadata">

**Author:** ![kirsten.chambers](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kirsten.chambers](https://forum.inductiveautomation.com/u/kirsten.chambers)\
**Post date:** [February 25, 2020, 3:08pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts/32579/2 "2020-02-25T15:08:28Z")

</div>

If you place your code surrounded by two sets of triple backticks (```) it will format correctly here on the forums. For example:

```  
your code here  
```

Would you mind editing your post so we know how your code is indented? Otherwise, we can’t accurately asses your code since indentation is integral to its logic.

---

<div class="post-metadata">

**Author:** ![twstevic](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@twstevic](https://forum.inductiveautomation.com/u/twstevic)\
**Post date:** [February 25, 2020, 3:11pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts/32579/3 "2020-02-25T15:11:44Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![kirsten.chambers](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kirsten.chambers](https://forum.inductiveautomation.com/u/kirsten.chambers)\
**Post date:** [February 25, 2020, 3:33pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts/32579/4 "2020-02-25T15:33:28Z")

</div>

Unless I’m missing something, I don’t see anything wrong with your logic right off the bat. Is there any other expression, script, or relationship that runs between your G\_Timer and G\_Counter\_1 tags that could be affecting your results?

I would recommend creating a [logger](https://docs.inductiveautomation.com/display/DOC80/system.util.getLogger) and using it to look at the value of `GC1value`. That will let you know what your values look like during your script execution and hopefully find the problem.

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [February 25, 2020, 4:50pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts/32579/5 "2020-02-25T16:50:23Z")

</div>

Since I see `system.tag.writeBlocking` you’re using Ignition 8.0.x so, try the following script.

```auto
if newValue.getValue() == 1:
	GC1value = system.tag.readBlocking(["[default]G_Counter_1"])[0].value
	GC1value += 1
	if GC1value > 9999:
		GC1value = 0
	system.tag.writeBlocking(["[default]G_Counter_1"],[GC1value]) 

```

---

<div class="post-metadata">

**Author:** ![twstevic](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@twstevic](https://forum.inductiveautomation.com/u/twstevic)\
**Post date:** [February 26, 2020, 1:13pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts/32579/6 "2020-02-26T13:13:03Z")

</div>

Well, I left last night before I saw these replies. Thank you.  
I had closed everything down before leaving and this morning when I restarted everything the script works. G\_Counter\_1 resets back to 0, as it should.

Rather odd, indeed.

---

<div class="post-metadata">

**Author:** ![twstevic](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@twstevic](https://forum.inductiveautomation.com/u/twstevic)\
**Post date:** [February 26, 2020, 1:17pm UTC](https://forum.inductiveautomation.com/t/running-gateway-scripts/32579/7 "2020-02-26T13:17:09Z")

</div>

When I first noticed G\_Counter\_1 incrementing higher than 9999 I was using the value in a transaction. I deleted the transaction so the counter was not referenced any other place in my project.
