Variables Overview

Overview

Variables are placeholders that store and manage different types of information, like numbers or text. They allow you to work with dynamic data throughout the app's blocks, enabling functionality such as displaying real-time information or tracking user interactions.

Variable Types

Thunkable supports three types of variables: app, stored, and cloud.

Variable TypeDescriptionData TypeExample

App Variables

Store data within an app session and are reset when the app is closed and re-opened.

Works for any data type.

The user's current score in a single-session game.

Stored Variables

Store data on the device. This data is saved between app sessions, so is suitable for data that you want to save long-term.

Works for any data type.

If your app offers multiple languages, the language your user wants to view content in.

Cloud Variables

Store data in the cloud in a Firebase database. This data can be accessed from multiple devices. Suitable for data your user may want to access from multiple devices.

Data must be stored as a string.

In a collaborative app where multiple users share information, game scores, or chat messages across different devices or users accessing the same application.

Variable names can only contain alphanumeric characters and underscore. Invalid characters may cause your app to crash.

App Variables

  • Store data within an app session and are reset when the app is closed and re-opened.

  • Work for any data type.

  • Example: The user's current score in a single-session game.

Video Tutorial

Stored Variables

  • Store data on the device. This data is saved between app sessions, so is suitable for data that you want to save long-term.

  • Work for any data type.

  • Example: If your app offers multiple languages, the language your user wants to view content in.

Video Tutorial

Cloud Variables

  • Store data in the cloud in a Firebase database. This data can be accessed from multiple devices. Suitable for data your user may want to access from multiple devices.

  • Data must be stored as a string.

  • Example: In a collaborative app where multiple users share information, game scores, or chat messages across different devices or users accessing the same application.

Video Tutorial

Firebase Realtime Database

By default, cloud variables are saved to the Thunkable default Firebase database, but we recommend you save them to your own private Firebase Realtime Database. Learn more here: Connect a Firebase Realtime Database.

Cloud Variables and Data

You can only save a piece of text or an object as a cloud variable.

To save a list as a cloud variable, use the "make text from list" block to convert the list to a piece of text.

When you retrieve this text from your cloud variable, you can convert it to a list with the "make list from text" block to work with it as a list in your app.

To save media as a cloud variable, use the Upload File block to upload it to Cloudinary and get a URL that points to it. You can save this URL as a cloud variable.

Statically vs Dynamically Named Variables

Statically Named Variables

A statically named variable is fixed. The value will likely change, but the name is constant.

You can initialize (create) variables with static names using the "initialize variable to" block. Initializing an app variable requires you to define an initial value. Stored and cloud variables initialize with null values.

Dynamically Named Variables

A dynamically named variable is one whose name is determined or created while the app runs rather than being predefined or fixed in the blocks. This allows you to generate variable names based on certain conditions, user inputs, or other dynamic factors. 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 helpful 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.

pageConnect a Firebase Realtime DatabasepageVariables Blocks

Last updated