Working with Scripts¶
Start a new script¶
When the Storage has been created an empty script is created in the Script View.
A script which is not listed in the data view can be accessed by:
Double click on the storage, or right click and select Edit Storage.
Once the storage open in the Data View the scripts within it can be edited.
To write a script:
Right click in the empty script editor and select Insert.
In the context menu two types of script templates can be selected. The templates provide a starting point for creating a more comprehensive script.
Existing scripts can also be copied and pasted into a new script and thereby provide a template for the new script.
Simple script template¶
Advanced script template¶
Modify a script¶
The script can now be modified:
- Modify the script name
- Modify the script description
- Insert script code
Code Complete¶
When writing scripts, code complete is available when using .NET assemblies like the MIKE OPERATIONS API.
Save a script¶
When the script has been modified it should be saved:
Click save in the Script editor's toolbar.
Note
Note: If the script contains syntax errors it cannot be saved.
Confirm the changes by pressing the Save button in the Confirm changes dialog.
The script will now appear in the group view and can be moved to a group or subgroup.
Note
Note that only scripts with a script tag with author and description will be shown in the script explorer.
Once a script has been saved, the script can be moved to a group or subgroup. The properties of the script are described in the properties dialog.
Lock/Unlock a Script Storage¶
Locking a script storage, can make sure that other users will not be able to edit and save a script storage while being edited by you.
Select Lock in the context menu of the script storage to lock the script storage.
When locking a script storage, the script storage will be automatically unlocked after 24 hours.
A lock icon will be shown indicating that the script storage is locked.
If user tries to save or delete a script storage locked by another user (a user with another user name or from another machine), the user will get a warning that it is not possible to save or delete the script storage.
Unlock the script storage to allow other users to edit and save the script storage.
Execute a script¶
A script can be executed in two different ways:
Right click on the script in the group view and select Run in the Context menu.
Open the script in the Script editor and select the script from the pull down menu, and click on the run menu in the toolbar of the Script Editor.
After execution of a script, the information about the execution is displayed in the Properties Editor.
Comment about input parameters:
Beware that when passing arguments to a script, the format has to match the expected type. For example, if a script has an attribute of type Single, it will not accept as valid value a number that can be considered as a Integer. In this example, passing the value 13 would fail while 13.0 would succeed.
Debug a script¶
Before a script can be executed, it often needs to be compiled.
If there are syntax errors it will not be saved.
Example of a syntax error upon saving is shown in the figure.
When the script has been modified it should be saved:
Click save in the Script editor's toolbar.
Note
Note: If the script contains syntax errors it cannot be saved.
When debugging a script it is convenient to place the debugger view below the script editor, so both editor and debugger are visible at the same time.
When debugging a script it can be analyzed in more detail by running the script stepwise in order to localize the error.
Breakpoints can be inserted to stop the execution and investigate variables and conditions, and subsequently continue the executing until the next breakpoint.
Insert breakpoints by clicking the mouse at the left column and in the line where the program should stop temporarily.
In the adjacent figure a break point is located at line 30.
When the execution stops at the breakpoint, the line will be highlighted in a yellow color, which indicates the current position of the execution.
Note: In the adjacent figure, the line above the breakpoint indicates that the script should print the following:
CalculateAverage('int')
.
In the debugger under the output tab, the printed statement is shown. Indicating it has passed the line containing the print statement.
Click at the Step Into menu in the toolbar (or press F11) to continue the execution
Note
Note: In the example the new current execution line at line 14 is highlighted yellow, and execution line from the function call in line 30 is highlighted green.
Click on the Call Stack tab in Script Debugger window to review the current Call Stack (which corresponds to highlighted lines from previous point).
Switch to the 'Watch' tab in 'Script Debugger' window and review the variable properties
When an unhandled exception error is detected it will be highlighted in red.
Click on the red exclamation mark menu in the toolbars to view exception error details (in this case division with zero).
Click on stop menu in the toolbar (or press Shift+F5) to stop the script execution.