# \[Tag Event Script\] Writing value from one UDT member (OPC) to another (Memory) using value change of Boolean tag

**URL:** <https://forum.inductiveautomation.com/t/tag-event-script-writing-value-from-one-udt-member-opc-to-another-memory-using-value-change-of-boolean-tag/85998>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [February 20, 2024, 9:48am UTC](https://forum.inductiveautomation.com/t/tag-event-script-writing-value-from-one-udt-member-opc-to-another-memory-using-value-change-of-boolean-tag/85998 "2024-02-20T09:48:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![keari0913](https://avatars.discourse-cdn.com/v4/letter/k/c77e96/32.png) [@keari0913](https://forum.inductiveautomation.com/u/keari0913)\
**Post date:** [February 20, 2024, 9:48am UTC](https://forum.inductiveautomation.com/t/tag-event-script-writing-value-from-one-udt-member-opc-to-another-memory-using-value-change-of-boolean-tag/85998/1 "2024-02-20T09:48:32Z")

</div>

**End Goal** : Accurately log fault occurences.

I have a UDT for powerflex 525s. I'm using the tag historian to store fault data by logging the string value for the **ActiveFaultDesc** UDT member. **Sample Mode** is set to "On Change". Originally the value on **ActiveFaultDesc** changed based upon the integer value of **FaultCode** which is tied to the **":I.Fault1Code"** tag from the PF525.

Most who are very familiar with the PF525 VFDs know that the **":I.Fault1Code"** tag serves as both the "active fault code", while the VFD is in a faulted condition and also the "most recent fault code", once the VFD is out of the faulted condition.

One of the problems that I ran into is that if the VFD experienced the same fault twice or more in a row, the **FaultCode** int value would not change leading to the **ActiveFaultDesc** value not changing either, resulting in those occurrences not being logged. If a different fault code occurred, then it would be logged.

I then added a UDT member, int memory tag **ActiveFaultInt**. Configured an event script on the **Sts\_DriveFault** boolean tag so that when it goes **True** , the value from **FaultCode** gets moved into **ActiveFaultInt**. Once **Sts\_DriveFault** goes **False** , a default value of 0 gets moved back into **ActiveFaultInt**. It works, but again, only when the value of **FaultCode** has changed since the last fault occurrence 🙃. It's as if the script won't run.

I added the **time.sleep()** because there is a slight delay between the time **Sts\_DriveFault** goes **True** and the new fault's int value is updated in the **FaultCode** tag. Without some kind of delay there would be even more inaccuracies in the stored fault data. If there is a better way to delay the script I'm open to ELI5 suggestions.

Please bear with me, I'm still new to scripting.

```auto
	import time
	path = "[.]ActiveFaultInt"
	
	if currentValue.value == True:
		time.sleep(.5)
		FaultCode = system.tag.readBlocking("[.]FaultCode")
		ActFltInt = system.tag.readBlocking("[.]ActiveFaultInt")
		
		if ActFltInt != FaultCode:
			system.tag.writeBlocking(path, FaultCode)
		
	elif currentValue.value == False: 
		system.tag.writeBlocking(path, 0)
		ActFltInt = 0
		FaultCode = 0	

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/b/bb538b86eb6272e7af52c05d842a45b540a70ca3.png)

---

<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:** [February 20, 2024, 1:37pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-writing-value-from-one-udt-member-opc-to-another-memory-using-value-change-of-boolean-tag/85998/2 "2024-02-20T13:37:36Z")

</div>

Don't subscribe to `FaultCode`. (Subscriptions do not guarantee deliver order or timing.) Use a direct OPC read after the fault trigger occurs. Do this in a gateway tag change event (project), not a tag valueChange event, as an OPC read can run for many seconds if there is a comms break at the wrong time.

Don't ever use any kind of sleep, or delay of any kind, in a tag event (on the tag).
