Automation Engine Script Guide > Introduction > First Steps > Script Functions

Script Functions

Objectives:
- Calling script functions
- Storing the script function's return code in a script variable
- Having the variable output in the activation protocol

Lesson 4

Script functions are AE Script elements that supply return codes. Many functions supply values and also execute particular actions. Script functions must not be placed at the beginning of a line and can only be used in combination with script statements. The UserInterface's script editor displays them in red.
A function's name is followed by parentheses ( ) that can include parameters.

 

The following lesson describes an arithmetic operation that is executed by using a script function.

The first step is to create a script variable with the data type "float" (see also lesson 3).

:DEFINE &result#, float

The script function DIV is used to perform a division. This function has two parameters: the numbers 1 and 2.
Number 1 is divided by number 2. The return code is the result of the division. To store it in a script variable, the script statement :SET is required.

The following line is the result of combining the script statement :SET, the script variable &result# and the script function DIV:

:SET &result# = DIV(1,4)

The result should now be output in the activation protocol.

:PRINT "Result: 1/4 = &result#" 

Result that is shown in the activation report:

2011-04-06 14:48:17 - U0020408 Result: 1/4 = +0000000000000000.2500000000000000

Another example of a script function is FORMAT which can now be used to format the result of the division. The following example removes unnecessary leading and final zeros:

:SET &format# = FORMAT(&result#,"0.00")
:PRINT "Formatted result: &format#" 

Activation protocol:

2011-04-06 14:48:17 - U0020408 Formatted result:0.25