While functions can be typed directly into the Map through a script, they need to be entered into every script that you want them to run from, within the Configuration.  

For multiple calls of the same function, there is an easier way – using what Statelake knows as an Include File or Script File.   You can think of an Include File as a file that contains independent snippets of code that are called or run more than once within the Configuration

Using include files means that any changes to those pieces of code need only to be made once – rather than hunt around and find every instance of the code within the Map, with the possibility of missing one that may cause some serious repercussions. 

For more information about Include Files, please refer to Include Files.

And it is not necessary to have all your functions in these files – you can have a mixture of functions either typed into the script, or called from within an include file.

The following is an example of user-defined functions called within the Statelake Map.   The function MyFunc is typed into the script, while MyFunc2 is contained in an include file called DaisyChain as illustrated by the ($I DaisyChain) reference at the head of the code. This code uses both MyFunc and MyFunc2.

($I DaisyChain)
 
function MyFunc(MyArg:string):string;
begin
Result := '>>>'+MyArg+'<<<';
end;
 
procedure ScriptEvent(var Value:variant);
begin
LogInfo('Hello World. I am here!');
LogInfo(StringReplaceAll('abc','a','x'));
LogInfo('This is the next');
LogInfo(MyFunc('Beth'));
LogInfo(MyFunc('1234'));
LogInfo(MyFunc2('5678'));
Sleep(2000);
end;

Then, inside the Include file called DaisyChain is the following code.

function MyFunc2(MyArg:string):string;
begin
Result := '***'+MyArg+'***';
end;

Include files are available to be accessed by any script within the configuration. 

However, if you want to have an Include File that is truly global and can be accessed by any configuration running on the same system, then the file can be stored on disk as a file in its own right.   Within the script, the location specified for these Include files would be the full directory path.

So rather than just saying ($I DaisyChain) the code would say ($I C:\Documents\ThisProject\DaisyChain).

Not only limited to functions, procedures can also be detailed and coded in these Include Files.