In this article, you will learn...
- How to start using variables
- How to utilize variables for more detailed analytics
- How to use variables alongside Triggers
Variables are the primary means of storing and referencing data in your Tulip apps.
When you want to store the value of a text input or access a pre-determined property of the app, you need a variable.
Or, when you want to calculate specific values based on past user decisions within the app, you need a variable.
Variables can either reset upon app completion or maintain their values through multiple completions depending on your specific use case.
When designing an app, a variable is often used to store the output from a device.
A variable can also be used as the condition for other triggers which will drive app logic, either by:
- Changing text displays
- Advancing to other steps, or...
- Prompting the operator to perform another task.
Variables are also needed to build detailed reports in the Analytics tool. If you want to individual data points from the operator, you will need to capture them in variables.
How to Create Variables
There are two primary ways to create a variable in the Tulip App Builder:
- Through the App Variables dialog
- Through the creation of a Trigger
Note: Check out the "Using Variables Within Forms" section in this guide to Form Steps to see how to add variables to Form Steps.
App Variables Dialog
In order to create a new variable through the App Variables dialog, follow these steps:
- Select the App tab from the Context Pane on the right of the App Builder.
- Click on the Sigma next to the “Variables” title.
3. The modal that opens when you click on the Sigma next to “Variables” shows you the variables in the current app, along with associated attributes as described below:
Type: The type of data being stored in the variable. This can take on one of the following values:
- Number (including decimals)
- Boolean (true/false)
- String (text)
- Interval (seconds)
- Image (URL or manual upload)
- Tulip User (administrator or operator)
- Datetime (timestamp)
Arrays and objects are complex variables. That means that they cannot be created within the App Variables dialog, but can be edited after they are created.
Arrays can be created via a "Mulitselect" field in a Form Step.
Objects can be created by storing the output of a Connector function in a variable.
For more detail on complex variables, see this guide to arrays and objects.
Where used: A hierarchy displaying the step name and trigger / widget where the variable is in use.
Persistent: Whether or not the data in the variable gets cleared when the app is completed. Please note: Persistent variables will be cleared after the "Complete and Go To Splash Screen" action.
Default Value: Set an initial value for the variable every time an operator starts the app
Delete: The delete action only becomes visible when the ‘where used’ section is empty in order to avoid breaking logical flow in the app.
4. Type a new variable name into the ‘Add a new variable’ text box and select the appropriate type from the Type dropdown.
If you want the data in the variable to persist when the app is completed, check the ‘Persistent’ checkbox and then click the "Add" button when finished. You should see your new variable appear immediately in the variable list below it, with nothing in the ‘Where Used’ column and the "Delete" button active.
When creating or editing a trigger, you can create a variable by following these steps.
- Create a new Trigger.
- Click the ‘Add new action’ button to open the new action section of the dialog.
- Select the 'Data Manipulation’ option from the "action type" dropdown along with the ‘Store’ option.
- Fill out the fields as they appear until the highlighted ‘location’ drop down appears. From there, select the ‘New variable…’ option.
5. Enter a name for the new variable and click the green check button next to the variable field. Then click the "Save button" at the bottom of the Trigger Editor. The variable you create will be available to edit in the App Variables dialog.
Variables in Form Steps
The last way to create a variable is through a Form Step. Check out the "Using Variables Within Forms" section in this guide to Form Steps to see how to add variables to Form Steps.
How to Use Variable Text
Once you create a variable, it becomes available for use in the actions and conditions of newly created and existing triggers in the same app. It is also available in the Text widget which is accessible from the Toolbar in the App Builder.
In order to access the value stored in a specific variable, select the relevant variable name from the Variables dropdown in the Context Pane.
It is worth noting that variables are stored on a per-app basis, so there are no step-specific variables and they cannot be shared between apps.
How To Delete Variables
To delete a variable, open the Variables Dialog from the Variables section in the App tab of the Context Pane.
Then, click the trash can icon on the far right of the modal to delete the variable.
Before deleting a variable, you must remove it from all Triggers and Variable text widgets where it is being used.