# Tag script help

**URL:** <https://forum.inductiveautomation.com/t/tag-script-help/63686>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [September 1, 2022, 4:37pm UTC](https://forum.inductiveautomation.com/t/tag-script-help/63686 "2022-09-01T16:37:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_kensett](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jason\_kensett](https://forum.inductiveautomation.com/u/jason_kensett)\
**Post date:** [September 1, 2022, 4:37pm UTC](https://forum.inductiveautomation.com/t/tag-script-help/63686/1 "2022-09-01T16:37:25Z")

</div>

First time doing a tag script  
Vision  
Version: **8.1.17**  
Background: I have AB PLC’s 5, 500 and 5000 that will all need to have the clock synced to within a few seconds. I want the following tag to be a “call” from the PLC’s at first scan then I will run it every hour to keep time.  
I can toggle the plc and see the tag go true and I can set numbers in the write tag and see them change in the plc. The Gateway\_Seconds tag is showing seconds. Can’t figure out what I am doing wrong or where to look to figure it out.

I have a Bool UDT from a plc with the following script.

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):  
“”"  
Fired whenever the current value changes in value or quality.

```
Arguments:
	tag: The source tag object. A read-only wrapper for obtaining tag
	     properties.
	tagPath: The full path to the tag (String)
	previousValue: The previous value. This is a "qualified value", so it
	               has value, quality, and timestamp properties.
	currentValue: The current value. This is a "qualified value", so it has
	              value, quality, and timestamp properties.
	initialChange: A boolean flag indicating whether this event is due to
	               the first execution or initial subscription.
	missedEvents: A flag indicating that some events have been skipped due
	              to event overflow.
"""
gatesec = system.tag.readBlocking("[default]Gateway_Seconds")[0].value
if currentValue.value == true:
	system.tag.writeBlocking(["[.]Clock Second Write"],["gatesec"])

```

---

<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:** [September 1, 2022, 4:38pm UTC](https://forum.inductiveautomation.com/t/tag-script-help/63686/2 "2022-09-01T16:38:37Z")

</div>

```auto
if currentValue.value == true:
	system.tag.writeBlocking(["[.]Clock Second Write"],["gatesec"])

```

Get rid of the quotes to reference the variable, otherwise you’re trying to write the string `"gatesec"`.

So like

```auto
if currentValue.value == true:
	system.tag.writeBlocking(["[.]Clock Second Write"],[gatesec])

```

---

<div class="post-metadata">

**Author:** ![jason\_kensett](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jason\_kensett](https://forum.inductiveautomation.com/u/jason_kensett)\
**Post date:** [September 1, 2022, 4:47pm UTC](https://forum.inductiveautomation.com/t/tag-script-help/63686/3 "2022-09-01T16:47:25Z")

</div>

Still a no go. Adding the quotes was my last attempt before asking for help. I am not getting any errors that I see but the udt opc tag Clock Second Write won’t change.

---

<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:** [September 1, 2022, 4:53pm UTC](https://forum.inductiveautomation.com/t/tag-script-help/63686/4 "2022-09-01T16:53:41Z")

</div>

Do you see anything in your gateway logs?

writeBlocking provides a list of result codes back. Try doing this to in your script console to see what is going wrong -

```auto
gatesec = system.tag.readBlocking("[default]Gateway_Seconds")[0].value
results = system.tag.writeBlocking(["[.]Clock Second Write"],[gatesec])
for result in results:
    print result.diagnosticMessage

```

And you should at least what is going wrong here.

---

<div class="post-metadata">

**Author:** ![jason\_kensett](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jason\_kensett](https://forum.inductiveautomation.com/u/jason_kensett)\
**Post date:** [September 1, 2022, 5:13pm UTC](https://forum.inductiveautomation.com/t/tag-script-help/63686/5 "2022-09-01T17:13:12Z")

</div>

Thank you very much. Knowing where to find the errors was the key. This was the answer.

```
gatesec = system.tag.readBlocking("[default]Gateway_Seconds")[0].value
if currentValue.value == 1:
	system.tag.writeBlocking(["[.]Clock Second Write"],[gatesec])

```

---

<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:** [September 1, 2022, 5:14pm UTC](https://forum.inductiveautomation.com/t/tag-script-help/63686/6 "2022-09-01T17:14:45Z")

</div>

Oh I should have caught that. For python its `True/False`. `true` isn’t anything, so you’re script was probably erroring out at the comparison line.
