# Best practices and pitfalls with Tag Event Scrips

**URL:** <https://forum.inductiveautomation.com/t/best-practices-and-pitfalls-with-tag-event-scrips/99355>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [December 3, 2024, 10:29am UTC](https://forum.inductiveautomation.com/t/best-practices-and-pitfalls-with-tag-event-scrips/99355 "2024-12-03T10:29:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![deon.korb](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@deon.korb](https://forum.inductiveautomation.com/u/deon.korb)\
**Post date:** [December 3, 2024, 11:50am UTC](https://forum.inductiveautomation.com/t/best-practices-and-pitfalls-with-tag-event-scrips/99355/2 "2024-12-03T11:50:28Z")

</div>

I use `system.util.invokeAsynchronous()` extensively in tag change scripts, as we were running into performance issues. The pitfalls Kevin mentioned about the guaranteed order of events does not apply to my use case.

Your example may be massive improved if refactored with the new reading functions to only read (blocking) and write (async) once.

Pseudo-code:

```python
val = currentValue.value
readlist = []
for i in range(1, 33):
                packPath = str(tagPath).replace("Battery/inNumberOfPacks","Pack{:02d}".format(i)) + "/Parameters.PackNumber"
		readlist.append(packPath)

values = system.tag.readBlocking(readlist)

writelist = []
writevalues = []
for i in range(1, 33):
      packNumber = values[i].value
      writelist.append(packPath + ".Enabled") #build packpath again
      writevalues.append(1 if val>=packNumberelse 0)
system.tag.writeAsync(writelist,writevalues)

```

This way you iterate quickly to build the list of tags to read, read blocking once, iterate through the tags read to build the results, and finally writing the results once. This assumes you don't have to wait after the write.

---

_[View the full topic](https://forum.inductiveautomation.com/t/best-practices-and-pitfalls-with-tag-event-scrips/99355)._
