Skip to main content
All CollectionsBlocks
How do I use variables in my project?
How do I use variables in my project?

Store data in an app session, on the device, or in the cloud

Matt from Thunkable avatar
Written by Matt from Thunkable
Updated over a week ago

A variable is used to store a piece of data in your app.

Types of Variables

Thunkable supports 3 types of variables:

  • App Variables: store data within an app session, and are reset when the app is closed and re-opened. Works for any data type.

  • Stored Variables: store data to the device. This data is saved between app sessions. Works for any data type.

  • Cloud Variables: store data to the cloud in a Firebase DB. This data can be accessed from multiple devices. Data must be stored as a string.

App variables are suitable for data that doesn't need to be saved between app sessions. An example would be the user's current score in a single-session game.

Stored variables are suitable for data that you want to save long-term. An example would be the language your user wants to view content in, if your app offers multiple languages.

Cloud variables are suitable for data that your user may want to access from multiple devices. An example would be if your user creates an account, and you want to store their data online.

Statically vs Dynamically Named Variables

Statically Named Variables

You can initialize (create) variables with static names using this block:

You can initialize an app variable to a specific value. Stored and cloud variables will initialize with null values.

You can retrieve blocks to set or get the value of these blocks from the Variables drawer.

Each statically named variable comes with a 'when [variable] initializes or changes' block:

This allows you to program something to happen every time the value of this variable changes. For example, every time a user's score in a game changes, you can display the new score on the screen.

Dynamically Named Variables

You can also create dynamically named variables. These variables do not need to be initialized.

You can use text or other variables to set the name of these variables.

Dynamically named variables are useful if you don't know what the name of this variable will be during app runtime. For example, you can save data related to a user account under the user's User ID. The user ID is generated when the user signs in to your app.

Cloud Variables - Connect to your Firebase DB

By default, data saved with cloud variables will be saved to a default Thunkable Firebase DB. To protect your app data, connect your Thunkable project to yoru own Firebase DB. Learn how to do this here.

Cloud Variables: Save Data in String Format

Data can only be saved to a Firebase DB as a string of text or as an object.

Did this answer your question?