Creating a New Script Object and Script Function
To be able to create and use script functions, you first have to create a script object.
Procedure
-
To create a new script object, click the button in the
Script Objects section in the
Scripting area of the Layout
in design mode.
The new script object is displayed in this section. It can be renamed from the (More) menu or by double-clicking the name as for widgets.
-
To create a new script function, click
(More) for the script object and choose Add
Script Function.
A new function is created and can be seen underneath the script object instance. The side panel for this new function is displayed too. Here you can modify the function name, description, arguments, and the type of return value. Click Done to close the side panel.
-
Edit the script function in the script function dialog.
In the Properties section, type in the following elements:
Element
Description
Name of the function
The name is mandatory and it validates according to the same rules as for global variables (name cannot be empty, cannot be a reserved keyword, cannot begin with a letter).
Description of the function
A brief description. Return Type of the function
Can be void, string, boolean, integer, number.
By default, the return type is set to Void. However, you can change this.
Besides the primitive types described above, you can also select a wide variety of non-primitive types in the dropdown box like Button, Category, Chart, Clock, DataSource, Table, UrlType etc.
Set as Array
Only activated if the return type is not void.
Click to create a new argument for the function. The argument dialog is displayed, where you can edit the following elements:-
Name of the argument
-
Type of the argument
By default, the arguments panel is automatically completed with a suggested argument name.. If the argument should represent a list of this type, set it to be an array.
To close the argument panel and return to the script function side panel, click Done.NoteAll modifications take effect immediately without your having to click Done, for example when you press enter on an input, or immediately after you switch the dropdown value or to an array. You can see the resulting signature in the signature panel at the top of the editor and in the script function panel in the Arguments section.
-
- Optional:
You can reorder the arguments by dragging and dropping them inside the panel.
This changes the order of the arguments in the defined function.
Example
The following example describes the return type and input parameters for the script function computeAverage.-
Name: computeAverage
-
Return Type: number
-
Arguments: value1, value2 and value3 (all of type number)
-
Script code: return (value1 + value2 + value3) / 3.0;