Running Gateway Scripts

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.

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?

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.

Thank you

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 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.

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

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]) 

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.

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.