Navigation:  Language Reference > Keywords >


Previous pageReturn to chapter overviewNext page

Variables are symbolic representations of numerical quantities that may change during simulation runs. Variables must be defined in 20-sim, using the variables keyword. After the keyword, lines with variable declarations can be entered. Every line must be finished by a semicolon (;). An example is given below:



 real interesting V {volume, m3};                // the volume of barrel 1

 real hidden D {length, m};                        // the length of part 1

 real x (min=0.0) {m};                        // the position of part x with a minimum value of 0.0




20-sim currently supports four types of variables: boolean, integer, real and string. These types must be specified explicitly. The use of the type real is shown in the example above.


By adding the keyword interesting after the variable type, a variable will be given special focus in the Variable Chooser. The Variable Chooser shows the complete list of variables of a model and is used to select variables for plotting. The keyword interesting is shown in the variable list, making it easier to find variables of special interest.


To prevent users from inspecting variables or decreasing the list of variables, the keyword hidden can be applied. This keyword should follow the data type.


To use the same variable in other submodels, the keyword global can be applied. This keyword should follow the data type.Note that the keywords oneup and global are mutually exclusive. Only one can be used.


The keyword oneup should be used after the type (real, boolean, integer) and keyword hidden and before the name of the variable. It is used to limit the scope of a variable. Note that the keywords oneup and global are mutually exclusive. Only one can be used.


To quickly find a variable in the Variable Chooser the keyword favorite can be applied. This keyword should follow the data type.

Variable Names

Variable names can consist of characters and underscores. A variable name must always start with a character. Variable names are case-sensitive. No reserved words may be used for variables. If a reserved word is used, an error message will pop-up while checking the model.


Right after a variable name you can enter annotations for the minimum value, range etc.

Variable Values

Variables cannot be assigned default values.

Quantity and Unit

If a variable is known to represent a physical value, you can define the corresponding quantity and unit. 20-sim will use this information to do a unit check on equations. The use of quantities and units is optional. In the example above the quantities volume and length are used with the units m3 and m.


If comment is added at the end of the variable declaration, it is shown in the Variable Chooser to facilitate the selection between variables.

Predefined Variables

20-sim has some predefined variables which have a special meaning.



 real interesting p1,p2,state;

 integer i;

 integer j;



 string filename;

 integer interesting i;

 real interesting state;

 boolean t,f;


Use the 20-sim naming convention for variable names.