Steps in Defining functions
The Functions tab is added to the Script Editor to define a new
function.
1. Add a new function by selecting the Functions tab
displayed in the Script Editor. The New function dialog will
be displayed, as shown in the screen-shot below. Specify the function
name, namespace, return type and arguments, if any, to be passed to
this function.
Function name: Name is the identifier by which it will
be possible to call the function. Any meaningful name without
white spaces can be specified as function name. The name must
not contain any white spaces.
Namespace: Related functions can be grouped under a name
based on their purpose, for easy maintanance. Any meaningful name
without white spaces can be specified as namespace. View
Screen-shot.
Return Type: Return type is the data type specifier of
the data returned by the function. If no data is returned by the
function, the return type must be specified as void.
Arguments (as many as needed): They allow to pass parameters
to the function when it is called. Each argument consists of a
data type specifier followed by an identifier, like any regular
variable declaration (for example: int a) The different parameters
are separated by commas.
For example, let us create a simple function to display a number.
Specify the function name as display. Since this function does
not return any argument, the return type is void. Argument
a of type int, will be passed to this function, when called.
Create the function by selecting the Create the Function button.
2. The function display will be added to the Functions
tree under the namespace test, as shown in the screen-shot below.
Select the function from the Functions tree and add the required deluge
statements to be executed, using drag-n-drop or Free-flow scripting.
For example, we add the Deluge statement Info to display a given
number. Select Save Script to save the function.

You can use the Execute Script option to test if your function
is executed as defined, by specifying the required values as arguments
to the function. For example, to execute the display function,
we specify a value for the argument (int a). On submit, the Info
input.a deluge statement is executed , as shown in the screen-shot
below:

Note: Select the Write Script option to define a function
by directly writing or pasting the script code in the Functions dialog,
as shown in the screen-shot below:

Name Space
In the screen-shot given below, Calculations is the namespace
that groups similar functions related to calculations. Here, CalculateDays,
CalculateHours etc are function names. If the function is called within
the application where it is defined, the namespace will be appended with
the word thisapp. If the function is called from a different application,
the namespace will be appended with the actual application name, where
it is defined.
For example, if the function CalculateDays is called from the
Sample application, the function call will be in the following
format: thisapp.Calculations.CalculateDays(),
where,
- thisapp refers to the current application,
- Calculations is the namespace,
- CalculateDays is the function name.
