Script Elements

In some situations, you may wish to define a complex function which cannot be readily implemented using the expression editing features supplied by GoldSim. For example, calculation of an output may require very complex logic which would be cumbersome to represent using a Selector element, or it may require a numerical solution technique (e.g., iteration); or perhaps you need to construct an array using complex logic.

A picture containing text, sign

Description automatically generated

GoldSim provides two separate ways to deal with such situations:

   You can develop separate program modules (written in C, C++, FORTRAN or other compatible programming languages) which can then be directly coupled with the main GoldSim algorithms. These user-defined modules are referred to here as external functions, and the elements through which they are coupled to GoldSim are called External (DLL) elements.

   You can specify a sequence of statements directly within the GoldSim interface using a Script element.

Although, for some complex calculations, an External (DLL) element may be required, for many applications a Script element can be used.  The key advantages of a Script over an External (DLL) is that 1) it does not require use of a separate programming language and interface; and 2) it is much more transparent (all of the “code” can be seen directly in GoldSim).

Scripts are created by inserting and editing statements or statement blocks, which may be variable definition statements, variable assignment statements, statements controlling the sequence of execution in the script (e.g., loops and if statements), or statements used for writing messages to the Run Log.  The Script element sequentially evaluates the specified sequence of locally defined statements to determine its output(s). 

   Note:  The Script element does not expect the user to learn or be familiar with a particular language.  As a result, scripts are not created using a text editor. Rather, statements are inserted and edited within a “controlled environment” within the element’s property dialog in which the user selects from a number of available statement types.  The syntax is already defined for each type of statement – the user simply specifies the attributes and properties for each statement via a dialog box when the statement is inserted. Statements can subsequently be moved, deleted, and edited.

To provide a quick idea of what a script looks like, a simple example in which a script is used to define a vector is shown below:

The topics below discuss the use of Script elements in detail.  The Script element is powerful, and, as a result, somewhat complex.  It is strongly recommended that you read through these topics carefully before attempting to build your own scripts.

   Note: In the topics that follow, the term “Script” (capitalized) refers to the element itself; the term “script” (lower case) refers to the list of statements defined by the user within the element.

Related Topics…

Learn more about: