App, Stored and Cloud Variables

In app creation, variables work like containers to hold numbers, phrases, the results of a calculation, a database call, or other important values in the app, in the mobile device itself or in the cloud. Instead of repeating these values in multiple places, a variable can be used wherever it is needed in your Blocks code.

When you create a variable, you'll have the choice between an app, stored and cloud variable. All variable types work across screens and the only difference is where they are stored.

App Variables

An app variable works across screens and is stored in the app itself. You can save any data type as an app variable. When you leave the app, the variable disappears.

Stored Variables

A stored variable also works across screens but is saved to the mobile device itself. This means that a stored variable can be retrieved from a previous session. A stored variable is especially useful for retrieving a user's previous setting. You can save any data type as a stored variable.

Cloud Variables

A cloud variable also works across screens but is saved to the cloud. Cloud variables can be used similar to saving and retrieving values to an online database and can be used to share data across users in the cloud. You can only save a piece of text or an object as a cloud variable.


Initialize a Variable When the App Starts

To create a variable when the app starts, you can use the block initialize (scope) variable (variableName) to, select your variable scope (app, stored, cloud) and give the variable a name. You'll have to connect a block to give app variables an initial value (in the picture above). We recommend placing these blocks in the initial app screen.

Set a Variable During an App Event

You can also set a variable within a block event, for example, within the when (Screen1) (Opens) block, as seen in the image above. Simply grab the set variable block and connect it to the value that you want it to be set to.

Retrieving a Variable Value

Once you have stored a value to your variable, you can retrieve it any time using a block like the one below (left set of blocks).

Updating When the Variable Initializes or Changes

Once you have created your variable, you can set it to update when the variable updates in your app. With Cloud variables, this block will also be triggered when the value of the Cloud variable is changed in your database. See the right set of blocks, in the image above.

Changing the Value of a Variable

Variables do not have to be fixed values and there may be times when you want to change your variable automatically like incrementing it by 1 after an event, by using the change (variableName) by [Value] block or changing its value entirely, by using the set (variableName) to [Value] block.