Understanding the Outputs of a
Script Element
By default, a Script element has a single primary output For an element with multiple outputs, the output that has the same name as the element.. The attributes of this output are defined in the main Script dialog.
It is also possible to define additional outputs for the element (with attributes and dimensions An output attribute for an element that defines the dimensionality (in terms of Length, Time and other fundamental dimensions) of the output.) when defining local variables within a script.
When you create a local variable, you can specify that you want it to be an output for the element by checking the Expose as Output checkbox (which by default is cleared):
For example, if a Script element (named Script1) had two local variables (X and Y), and only X was exposed as an output, then outputs of the Script element would look like this:
The primary output (referred to as Result in the script) would be referenced outside of the Script element as Script1. The secondary output For an element with multiple outputs, an output that has a different name than the element. X would be referenced outside of the Script element as Script1.X. The other local script variable (Y) could not be referenced outside of the Script element.
As is the case for other GoldSim elements, you can check the checkboxes at the bottom of a Script element dialog to save "Final Values" and/or "Time Histories" of all the exposed outputs (including the primary output).
There is an important difference in the behavior of the
primary output and any other exposed outputs. The primary output of a
Script element is a
This has an important implication for how the variables can be used in a script. In particular, the value of the primary output is "remembered" between updates of the element. As a result, in a script you could create a Variable Assignment such as "Result = ~Result + 1" as the very first statement. The expression would use the previous value of the Result when it was evaluated. This is not possible for any of the other script variables, since they require a Variable Definition statement which initializes the variable every time the Script element is updated.
Note: User-defined local script variables cannot reference themselves in a Variable Definition statement (e.g., X = ~X + 1 would be invalid, as there is no existing initial value of X to reference in this case).
If you would like additional outputs of the Script element to be able to "remember" their previous update (and hence behave like state variables with initial conditions), you can do so by referencing the Script output in a Previous Value element outside of the Script element (and then referencing the Previous Value inside the script).