How to Configure Variables

When you create a new robot, you usually start by configuring its variables. Of course, you can reconfigure the variables at any time during the robot's lifetime, e.g. if, at some point, you want to change the initial value of a variable.

You configure the variables of the robot in the Variables View, located below the Step View in the Robot Editor. The variables that you specify become part of the robot state given as input to the first step of the robot.

The Variables View shows a list of variables, together with details on the selected one. A variable may be set as an input variable in which case the icon is shown next to it. Also, a variable can be set as being global in which case the icon will be shown next to it (how to configure a variable is described below). The Variables View shown below contains three variables: one input variable, one normal variable, and one global variable.

The Variables View

The Variables View shows the values of the variables at the current step. Because these values result from the execution of the robot, you cannot change them directly. However, you can add or remove variables.

There are two ways to add a new variable: you can click the button at the bottom of the Variable View, or you can right-click the Variable View and select a type from which the variable should be created as shown in the figure below.

Adding a new variable

Adding a variable is done using the variable configuration dialog. If the variable is added using the right-click method, where a type is already chosen, the dialog opens with the type pre-selected. The variable configuration dialog is shown in the figure below. This is also the dialog you get if you want to configure an existing variable, either by double-clicking it or by clicking the button.

The Variable Configuration Dialog

In this dialog there are a number of options. Firstly, you can choose a name for the variable. The name must adhere to some standards, for example it is not allowed to contain whitespace. When you click the 'OK' button, the dialog will tell you if the name is invalid, and you must change it to continue (or click 'Cancel'). Secondly, you must select a type for the variable. Types and their connection to variables are described here. When you have selected a type, a number of input fields appear, depending on which attributes the type has. These fields can be used to provide the variable with initial values. You do not have to manually give the variable a name. If you have not entered a name, when clicking 'OK' the dialog will ask you if you want to generate a name from the type name.

Note: the variable configuration dialog allows you to edit initial values. In other words, this dialog does not, as the Variables View, show current values. The values you provide are those that the variable has at the start of the execution.

The two remaining options in the dialog are the two checkboxes 'Global' and 'Use as Input'. These are used to configure the important properties of whether a variable should be used as input to the robot, and/or whether it should be global.

If a variable is used as input, it makes it possible to supply the robot with values for that variable when running it on a RoboServer. This means that if the variable has been selected as being input, the values entered for its attributes in the dialog should be regarded as test input and are only used when you are working with the robot in Design Studio. When the robot is run on RoboServer, the input values will be overridden (i.e. replaced) by values supplied by the client that runs the robot. Please note that variables of simple types cannot be used as input, as their usage is as temporary variables, internal to the robot. More on using input variables can be seen here.

The 'Global' checkbox marks the variable as global, meaning that the variable keeps its value during the entire execution of the robot. This is different from normal variables, whose values are not kept across loop iterations and branches.

Global variables provide a way to create counters and do other kinds of computation across iterations and branches. Global variables can also be used for accumulation of data across iterations or branches, such as accumulating a text consisting of comma-separated values.

Note: In Design Studio, the values of the global variables depend on which specific steps you have executed to get to the current step. Unless care is taken to execute the right sequence of steps, the values will be different from when the robot is actually executed.

To remove a variable, simply right-click it and chose 'Remove'. Alternatively, select a variable and click the button below the list.