## Variables

Variables are pieces of data that can be written and read through the events' system. A Variable value can be interpreted as a string, number, date, collection of Data Master's records or anything depending on the calculations applied on it. Variables' lifespan is that of the simulation of the prototype.

### Creating variables

To create a new Variable, first select the option 'Variables' from the View menu to show the corresponding panel. Then follow the steps:

1. Click on the magenta 'plus' button. A dialog will appear.

2. Introduce a name for the Variable in the input 'Name'. The name of the Variable must be unique per prototype in order to identify them properly.

3. (Optional) Introduce a default value in the input 'Default Value'. This will be the value the Variable will take when starting the prototype's simulation.

4. Click on Ok to create the Variable or click Cancel to cancel the changes.

### Modifying variables

To modiy the name or default value of an existing Variable, double-click on it on the Variables panel or right-click on it and select 'Edit'. Modify the parameters in the dialog and click on Ok.

### Deleting variables

To delete a Variable, right-click on it on the Variables panel and select 'Delete'.

### Setting a value

You can store any kind of information in a Variable during simulation using events and interactions. Specifically, storing a value to a Variable must be done through a 'Set Value' action using the desired variable as the action's target. Justinmind Prototyper offers you two different ways to create this action for a Variable:

#### Using drag and drop

To store the value from a screen's widget to a Variable just drag the widget and drop it on the desired variable on the Variables panel. This will create an 'On page unload' event with an action that sets the widget's value to the variable.

#### Creating the action manually

To store the value from a screen's widget or any other data source (including the result of complex calculations) use the Events panel to create a 'Set Value' action (see Actions for more information about this action). Type a constant as a value or click on the 'Calculated' button to use a data source or construct a calculation.

### Getting the value

You can display the contents of a Variable during simulation also using a 'Set Value' action and setting the Variable as the data source. Justinmind Prototyper offers you two different ways to create this action:

#### Using drag and drop

To display the value of a Variable in a screen's widget just drag the Variable and drop it on the screen's widget. Notice that the target widget must be compatible with the Variable's value type. This will create an 'On page load' event with an action that sets the Variable's value to the widget.

#### Creating the action manually

To display the value of a Variable on a screen's widget use the Events panel to create a 'Set Value' action (see Actions for more information about this action). In the Interactions dialog select the screen's widget as the action's target, click on the 'Calculated' button and create an expression using the Variable as the only data source.