# Help with scripting for tags in ignition

**URL:** <https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219>\
**Category:** Ignition\
**Created:** [May 31, 2022, 3:55pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219 "2022-05-31T15:55:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_Moody](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Sean\_Moody](https://forum.inductiveautomation.com/u/Sean_Moody)\
**Post date:** [May 31, 2022, 3:55pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/1 "2022-05-31T15:55:27Z")

</div>

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 = system.tag.read("[.]…/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!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 31, 2022, 3:57pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/2 "2022-05-31T15:57:02Z")

</div>

> [@Sean\_Moody](#):
>
> current.value and current.value

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

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 31, 2022, 4:21pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/3 "2022-05-31T16:21:32Z")

</div>

Plug for - [Browse the Lesson Library at Inductive University](https://inductiveuniversity.com/courses/ignition-overview/8.1)

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

---

<div class="post-metadata">

**Author:** ![Sean\_Moody](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Sean\_Moody](https://forum.inductiveautomation.com/u/Sean_Moody)\
**Post date:** [May 31, 2022, 4:45pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/4 "2022-05-31T16:45:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sean\_Moody](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Sean\_Moody](https://forum.inductiveautomation.com/u/Sean_Moody)\
**Post date:** [May 31, 2022, 4:46pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/5 "2022-05-31T16:46:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [May 31, 2022, 5:00pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/6 "2022-05-31T17:00:48Z")

</div>

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

```python
if previousValue.value != currentValue.value and currentValue.value == 60:
	# Are you needing to move two folders up in the hierarchy?
	# If so, use `../../`
	qualifiedValue = system.tag.read("[.]../../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)

```

---

<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:** [May 31, 2022, 5:13pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/7 "2022-05-31T17:13:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sean\_Moody](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Sean\_Moody](https://forum.inductiveautomation.com/u/Sean_Moody)\
**Post date:** [May 31, 2022, 5:32pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/8 "2022-05-31T17:32:43Z")

</div>

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.

---

<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:** [May 31, 2022, 5:35pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/9 "2022-05-31T17:35:22Z")

</div>

> [@Sean\_Moody](#):
>
> `if initalChange == true:`

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

```auto
if initialChange:

```

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

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 31, 2022, 5:56pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/10 "2022-05-31T17:56:53Z")

</div>

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

```auto
if not initialChange:

```

otherwise previousValue is `None`

---

<div class="post-metadata">

**Author:** ![Sean\_Moody](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@Sean\_Moody](https://forum.inductiveautomation.com/u/Sean_Moody)\
**Post date:** [May 31, 2022, 6:13pm UTC](https://forum.inductiveautomation.com/t/help-with-scripting-for-tags-in-ignition/60219/11 "2022-05-31T18:13:29Z")

</div>

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.
