# User Defined Function - Best Practice

**URL:** <https://forum.inductiveautomation.com/t/user-defined-function-best-practice/24898>\
**Category:** General Discussion\
**Tags:** scripting\
**Created:** [May 10, 2019, 6:40pm UTC](https://forum.inductiveautomation.com/t/user-defined-function-best-practice/24898 "2019-05-10T18:40:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timothy.tickner](https://avatars.discourse-cdn.com/v4/letter/t/e480ec/32.png) [@timothy.tickner](https://forum.inductiveautomation.com/u/timothy.tickner)\
**Post date:** [May 10, 2019, 6:40pm UTC](https://forum.inductiveautomation.com/t/user-defined-function-best-practice/24898/1 "2019-05-10T18:40:42Z")

</div>

Hi All,

I’m creating some functions that split a string out into categories and then break those categories into buckets. They are all identical from the category level down, so I’m using a UDT. I currently have all of my functions in a Project Script called ‘speedway’, so I should be able to access those functions by calling them with `project.speedway.function()`. This works in the script editor but once I put the function call in a ‘Value Changed’ Tag Event, it starts getting wacky and unreliable.

Is it better to define a function inside of the Value Changed script or is what I’m doing okay and there’s just a way to make it more reliable?

Thanks in advance!

EDIT: I will add that it could come from my UDT structure and the way that I’m entering arguments for the function. I have two parameters in my UDT, Antenna Number and Reader Number, both are integer values. When I call the function ( antenna\_hold() ) in the Value Changed, I format the call like this:

```auto
project.speedway.antenna_hold("[.]Reader", "[.]Antenna")

```

I’m not sure if there’s a better way to use the UDT parameters. Right now I’s done via two expression tags, Reader and Antenna that take the value of Antenna Number and Reader Number UDT parameters.

---

<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 10, 2019, 7:10pm UTC](https://forum.inductiveautomation.com/t/user-defined-function-best-practice/24898/2 "2019-05-10T19:10:07Z")

</div>

Tag events cannot call project scripts. Only shared scripts are available. Consider (strongly!) using a gateway tag change events (in the project) instead.

---

<div class="post-metadata">

**Author:** ![timothy.tickner](https://avatars.discourse-cdn.com/v4/letter/t/e480ec/32.png) [@timothy.tickner](https://forum.inductiveautomation.com/u/timothy.tickner)\
**Post date:** [May 10, 2019, 7:15pm UTC](https://forum.inductiveautomation.com/t/user-defined-function-best-practice/24898/3 "2019-05-10T19:15:52Z")

</div>

Got it, thanks.

What about using UDT parameters in a function call? Is that possible? It doesn’t like when I call my ‘Antenna Number’ parameter using the typical {Antenna Number} format.
