How To Create And Use Variables
  • 06 Oct 2023
  • 14 Minutes to read
  • Contributors

How To Create And Use Variables


Article Summary

Overview

Here's how to get started with Variables and use them within your apps.

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:

  1. Changing text displays
  2. Advancing to other Steps, or...
  3. 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 Editor:

  • 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:

  1. Select the App Tab from the Context Pane on the right of the App Editor.
  2. Click on the X next to the “Variables” title.

  1. The modal that opens when you click on the X next to “Variables” shows you the Variables in the current app, along with associated attributes as described below:

How To Create And Use Variables_471418756.png

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)
  • Text
  • Integer
  • Interval (number of seconds)
  • Image (URL or manual upload)
  • Tulip User
  • Datetime (timestamp)
  • Station
  • Machine
  • Array (of any variable type listed)
  • Object
  • Color

Objects are complex Variables. They cannot be created within the App Variables dialog.

Arrays can be created via a "Mulitselect" inputs.

Objects can be created by storing the output of 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.

Clear on Completion: Whether or not the data in the variable gets cleared when the app is completed. Please note: these variables will be cleared after the "Complete and Go To Splash Screen action.

Save for Analytic: This toggle will be on by default. If you do not want a variable to be sent to an analysis for any reason, you may uncheck this box. Some variables may only be used for app logic, and are not needed in analytics. In these cases, it is best practice to not send them to analytics. Un-toggling non-essential variables may also help your analytics load faster as there will be less data to load in high-volume scenarios.

Default Value: Set an initial value for the variable every time an operator starts the app

Delete a variable: The delete action only becomes visible when the ‘where used’ section is empty in order to avoid breaking logical flow in the app.

Delete unused variables: The delete unused variables action erases all variables with an empty 'where used' section. Click on these three dots to prompt the 'Delete unused variables' window.
new2.png
This window will appear.
new3.png

  1. Click Create Variable and type a new variable name into the variable name 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, un-toggle the ‘Clear on Completion’ toggle and then click the "Create" 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.

Trigger Editor

When creating or editing a Trigger, you can create a Variable by following these steps.

  1. Create a new Trigger.
  2. Click the ‘Add new action’ button to open the new Action section of the dialog.
  3. Select the 'Data Manipulation’ option from the "action type" dropdown along with the ‘Store’ option.
  4. Fill out the fields as they appear until the highlighted ‘location’ drop down appears. From there, select the ‘New variable…’ option.

  1. 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.

More Details on Persistent Variables

Persistent variables allow you to save a value in a Variable across multiple app Completions.

Persistent variables save values relative to each the device running the app. They will not be overwritten if the app is used on multiple devices simultaneously.

So, if you have a visual andon app with a persistent variable that runs on 5 production lines, each line supervisor can update the variable on their app and the values will not be overwritten or conflict. They exist independently on each tablet running the Player.

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 Editor.

In order to access the value stored in a specific variable, select the relevant variable name from the Variables dropdown in the Context Pane:

You will be prompted to select your Datasource:

  • Variable: Any variable in your app that you've created
  • App Info: Variables that are automatically logged in your app (Ex: Logged-In User Name, Time Elapsed On App and Step Name)

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.

Use the Filter By search box to find the variable you wish to delete.

Then, click the ellipsis icon on the far right of the modal to delete the variable.

Note to delete a variable, you must remove it from all Triggers and Variable text widgets where it is being used.

Further Reading


Did you find what you were looking for?

You can also head to community.tulip.co to post your question or see if others have faced a similar question!


Was this article helpful?