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

<div align="left"><figure><img src="/files/ui8SzPPwyds48DlFBjH4" alt="" width="262"><figcaption></figcaption></figure></div>

| Variable Type    | Description                                                                                                                                                            | Data Type                        | Example                                                                                                                                                        |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 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. |

{% hint style="danger" %}
Variable names can only contain alphanumeric characters and underscore. Invalid characters may cause your app to crash.
{% endhint %}

## App Variables

* Store data within an app session and are reset when the app is closed and re-opened.&#x20;
* Work for any data type.&#x20;
* Example: The user's current score in a single-session game.

### Video Tutorial

{% embed url="<https://www.youtube.com/watch?v=3M9F3X1bCnA>" %}

## 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

{% embed url="<https://www.youtube.com/watch?v=tdgVeck-sOI>" %}

## 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

{% embed url="<https://www.youtube.com/watch?v=KvFvSkG6G-k>" %}

### 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](/blocks/blocks/variables-overview/connect-a-firebase-realtime-database.md).

### Cloud Variables and Data

You can only save a piece of [text](/blocks/blocks/text.md) or an [object](/blocks/blocks/objects.md) 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.

<div align="left"><img src="/files/w3gUdL8DOyyWE8qKoOmY" alt=""></div>

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.

![](/files/ROeHc1yvWx1yXoAsDLRR)

To save media as a cloud variable, use the [Upload File](/blocks/app-features/files-blocks.md#upload-file-to-the-cloud) 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 <a href="#h_233de41291" id="h_233de41291"></a>

### Statically Named Variables <a href="#h_52dcfd2a30" id="h_52dcfd2a30"></a>

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

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.

<div align="left"><figure><img src="/files/OH9lbjtWzfZJjzXRsUPC" alt="" width="337"><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/FXcbmy5fErePPE78JWcS" alt="" width="288"><figcaption></figcaption></figure></div>

### Dynamically Named Variables <a href="#h_f4365bf1bf" id="h_f4365bf1bf"></a>

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.

<div align="left"><figure><img src="https://thunkable-d69e866131e6.intercom-attachments-1.com/i/o/416240119/21af4baaac17ea5920972405/assets-2F-LAn5scXl2uqUJUOqkJo-2F-MYxbaVrv1axI8XSgT2j-2F-MYxceqYcxKvKWSoQIOm-2FScreen-20Shot-202021-04-23-20at-208.29.10-20AM.png" alt="" width="563"><figcaption></figcaption></figure></div>

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.

## Related Docs

{% content-ref url="/pages/HwbddoQgzvB5bkEy2dXD" %}
[Connect a Firebase Realtime Database](/blocks/blocks/variables-overview/connect-a-firebase-realtime-database.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LZ7M7ddcvOZeNeUNoyw" %}
[Variables Blocks](/blocks/blocks/variables-overview/variables.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.thunkable.com/blocks/blocks/variables-overview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
