Where to define JavaScript functions & variables

Most large TDI solutions have a number of JavaScript functions, and many have global variables. There are many places where these could be defined and used: script components, hooks etc. So what is the 'best' place to define functions and variables?

If you look in the left-hand pane of the config GUI, you will find a container labelled Scripts. This is a very good place to build a Script Library. Scripts held in the library can be included as prologs in AssemblyLines: they are run before the first prolog hook in the AssemblyLine when it is started (as shown here in this snippet from the TDI FlowDiagrams).

ALFlow.jpg

This allows code to be efficiently used in multiple AssemblyLines. Note that since each AL has its own dedicated Script Engine, you cannot share global variables between them - merely their definition.

Each Script in the Library is typically either a single function (if it's a big one), or a container for a related set of functions and variables - think of it as a package to do a particular job.

Scripts in the library have a Config tab, where the script can be declared to be implicitly included in all AssemblyLines.

TDI 7

ImplicitlyIncludeScript.jpg

TDI 6

ImplicitlyIncluded.jpg

Selecting this checkbox declares this Script as a global prolog. However, an AssemblyLine has a checkbox in its Config tab for choosing to use global prologs or not.

TDI 7

ALSettings.jpg IncludeGlobalPrologs7.jpg

TDI 6

IncludeAllGlobalPrologs.jpg

Furthermore, Scripts can be explicitly named for inclusion.

TDI 7

IncludeAdditionalPrologs7.jpg

TDI 6

ExplicitlyInclude.jpg

-- AndrewFindlay - 21 Dec 2005

-- EddieHartman - 1 Mar 2011
Topic revision: r2 - 21 Dec 2005, EddieHartman - This page was cached on 05 Aug 2023 - 19:02.

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TDI Users? Send feedback