Analytica Script
Analytica Script is a variant of the Analytica modeling language used in Definitions. It is of value to advanced users, and may be ignored by most users. It has some slight differences in syntax, and a set of Scripting Commands not available elsewhere. Most useful, lets you assign new definitions and other attributes to global variables.
You can use Scripts in:
- The Script Attribute of Buttons. This script is executed when the end user clicks the button.
- The Typescript Window: Press control+' (control+apostrophe) to open this window. It offers a command line interface to Analytica.
- In the special function EvaluateScript(script), which may be used in normal Analytica language. It evaluates its text parameter, script, as a script, and so lets you execute a script anywhere -- very powerful and a bit dangerous.
Button Scripts
You create a button in a Diagram like any other object type: In Edit mode, drag the button icon from the far right of node type toolbar to the position on the diagram you want (or press control-0).
Double-click the button to open its Object Window. Now you can review and edit its Script attribute.
Script syntax
Each line in a Script may be a standard expression from the Analytica language, such as a call to a function. One difference from Analytica language syntax, is that you can put multiple lines with no ";" or other separator between lines (other than newline).
Another key difference is that you can put an assignment to a global variable, e.g.
Y := 10 + 100 Definition OF Y --> 10 + 100
When you execute the script (e.g. click the button), it will assign X + 100 as a new definition to Y. If you put he assignment in parens, it assigns the value, rather than the expression:
(Y := X + 100) Definition OF Y --> 110 Defeinition Y
A third key difference of Scripts, is that you can use a variety of Script commands, e.g.
Open Object Y
will open the Object window of Y. Script commands take a list of parameters, usually object names, without parens and without separating commas.
For more on Scripts and Script Commands, see Scripting_Guide.
Assignments
Analytica does not normally let you assign a new value to the Definition (or other Attribute) of a Global variable (or other Object). This is to maintain the no side-effects rule, which makes Analytica models much easier to understand and debug than normal programs. Computer scientists would say it is a functional rather than procedural language.
But, sometimes you do want to write a procedure that makes assignments to Global (i.e. nonlocal) variables. You may also include assignments to Globals in a Function that is called from a Button script -- or from a Function that is called from a Function called from a Button script, etc. In this case, the end user is explicitly pressing the button and initiating the change to the model -- and so, side-effects are permissable.
Unlike normal Analytica language, you may
Enable comment auto-refresher