Help with scripting for tags in ignition

Hey all, this is my first ignition project so excuse me if this question is rather obvious, but I have this tag (called ProcessIndex) whose value maxes out at 60 when a process is completed, and I want that when the value reaches 60 it increases the value of another tag (called Compelted_Processes) by one. To do this I wrote a script under ProcessIndex that is as follows:

if previousValue.value != current.value and current.value == 60:
value ="[.]…/Data History/Completed Processes")
value += 1
system.tag.write("[.]…/Data History/Completed Processes", value)

However, this does not seem to work and I tried using previous posts and the ignition manual to figure out why, but I still cannot find out why this is not working. Any help would be appreciated!

This might need to be currentValue.value, rather than current.value.

Plug for - Browse the Lesson Library at Inductive University

If you haven’t gone through these videos yet, it will explain a lot about Ignition.

That would make sense but unfortunately upon changing it and applying the change my Completed_Processes tag is still 0 and not increasing.

I have watched some videos from the lesson library but not many videos over the scripting so I will probably do that, and see if I can find my solution from the videos.

Keep in mind that is going to return a QualifiedValue object. I’d adjust your script to be something like the following:

if previousValue.value != currentValue.value and currentValue.value == 60:
	# Are you needing to move two folders up in the hierarchy?
	# If so, use `../../`
	qualifiedValue ="[.]../../Data History/Completed Processes")
	# Notice that we must use the `.value` off of `qualifiedValue` to get our new primitive value
	newValue = qualifiedValue.value + 1
	system.tag.write("[.]../../Data History/Completed Processes", newValue)

You shouldn’t ever use previousValue.value if you haven’t checked initialChange. previousValue is None when initialChange is True, breaking your script.


Thank you for that, I will be sure to always check the initalChange now. I wrote this line of text to see if initalChange was true and if that was breaking my script:

if initalChange == true:
	system.tag.write("[.]../../Data History/Completed_Processes", 1)

However, the Completed_Processes tag is still reading 0 so I assume the initalChange is false and is not breaking my script but please correct me if this line of reasoning is inccorect.

This is not valid python. Python True is case sensitive. But even better is simply

if initialChange:

You should look in your gateway log for error reports from your scripts. (Mostly the error will only appear once.)

Though I think actually you want to insure it isn’t the initial change, so

if not initialChange:

otherwise previousValue is None

1 Like

I apologize, I am used to writing code in c++ and not python so that is a mistake from my c++ background. I will be sure to go back and check my syntax for the rest of my code to see if I made a similar mistake.