Variables

Home Scripting Variables

A variable is a named container for a value.

Variable names are more limited than field names: Only sequences of uppercase and lowercase letters, digits and the underscore character "_" are allowed as variable names, with the further restriction that the name must not start with a digit.

The following are legal variable names:

a  amount  target_card_name  f55

The script language of MoStacks is only very weakly typed: Variables have no fixed type per se, but can just assume values of any types. If a variable holds a string, and you assign it an integer, it just switches its type silently.

There are no variable declarations; just use variables.

There are two ways to set the value of a variable. The traditional, more HyperTalk-like way is using put ... into:

put 5 into a
put "hello" into greetings_text

You can also use the more direct and less verbose assignment operator =:

a = 5
greetings_text = "hello"

The scope of a variable is limited to the script where it occurs. Variables in different scripts with the same name have nothing in common and always hold two distinct values. When a script terminates all variables and their values vanish. If you want to keep something, put it into a field.

Please not that the rather permissible behaviour regarding variable use and variable types is very simple and straight-forward, but has also certain drawbacks. E.g. typos in variable names can be a problem, because MoStacks sees two different variables (or even more) in such cases where there should be only one variable, without any warning or even an error message. One can't have everything.)