Debugging Scripts

In order to create and test scripts (particularly those with complex branching and looping), it is necessary to be able to step through the script to debug it.

GoldSim facilitates this by allowing you to create breakpoints in your script. A breakpoint provides a mechanism for pausing a simulation in the middle of a script, and subsequently allowing you to step forward (line by line), abort the calculation, or resume the calculation.

To insert a breakpoint in a script, select (highlight) the line where you would like to insert the breakpoint and press F9, or right-click and select Breakpoint. (You can remove a breakpoint by pressing F9, or right-clicking and selecting Breakpoint again). Lines with breakpoints have a red background in the script statement list. In the example below, there is a single breakpoint inserted (at line 3):

When you run the model, at the point when a breakpoint is reached, the model will pause, and the Script element will be opened.

When a script is paused at a breakpoint, you will notice that the buttons at the bottom of the Script dialog differ from those that are displayed when the model is in Edit Mode The state of a model when it is being edited and does not contain simulation results.:

The next line to be evaluated is outlined in black. Hence, when you first reach a breakpoint, the line where the breakpoint was inserted will be outlined in black. Note that a line that is outlined in black has not yet been evaluated. The calculation is actually paused immediately prior to that line.

From the paused state in a Script element you can do the following to debug the script:

Breakpoints are not saved with the model. That is, once you close the model file, all breakpoints are intentionally removed. You will have to re-insert them if your debugging takes place over multiple GoldSim sessions.

In some cases, in order to fully understand and debug a script, you may want to print it out. You can do this from a button on the Script dialog.

Log statements, which allow results and text to be written to the model Run Log Text that is stored with a GoldSim model once it has been run. It contains basic information regarding the simulation, and any warning or error messages that were generated., are also useful for debugging.