📐
Thunkable Docs
Build an AppDrag and Drop DocsSnap to Place Docs
Snap to Place
Snap to Place
  • 👋Welcome to Thunkable Docs
  • 👶Getting Started
    • Signing In
    • Your Thunkable Projects Page
    • Tutorials
    • Live Test your App
  • 🆕Create New Project
    • Project Settings
    • Project Assets and Sizes
  • Thunkable Sample Projects
  • Public Gallery of Projects
  • 🛠️ Components
  • 🔘User Interface
  • Button
  • Label
  • Text Input
  • List Viewer
  • Web Viewer
  • Switch
  • Slider
  • Alert
  • Loading Icon
  • Date Input
  • Time Input
  • PDF Reader
  • Rating
  • 📊Data Viewers
  • Data Viewer List
  • Data Viewer Grid
  • Custom Data Viewer Layout
  • Data Sources
  • 📐Layout
  • Top Tab Navigator
  • Bottom Tab Navigator
  • Stack Navigator
  • Drawer Navigator
  • Screen
  • Row
  • Column
  • 📷 Image
  • Image
  • Photo Library
  • Camera
  • Barcode Scanner
  • Image Recognizer
  • Animation by Lottie
  • Video
  • Video Recorder
  • 🗄️ Data
  • Local Storage
  • Local DB
  • Realtime DB by Firebase
  • Airtable
  • Media DB by Cloudinary
  • File Picker
  • Web API
  • 🌍Location
  • Maps by Google and Apple
  • Location Sensor
  • 💲Monetization
  • Ads by AdMob
  • In-App Purchase
  • 🌐Sensors
  • Gyroscope
  • Magnetometer
  • Accelerometer
  • Timer
  • Bluetooth Low Energy
  • 🔊Voice
  • Sound
  • Text to Speech
  • Speech Recognizer
  • Translator
  • Audio Recorder
  • 🤝Social
  • Share
  • Email Sign In by Firebase
  • Push Notifications by One Signal
  • 🎮Gaming
  • Canvas
  • Sprites
  • Sprite Gallery
  • Canvas Label
  • 🤖Gaming Blocks🎮
  • Events
  • Motion
  • Looks
  • Direction
  • Sensing
  • Add & Remove
  • Stage
  • Canvas Label
  • 🤖Blocks
  • Control
  • Logic
  • Math
  • Text
  • Lists
  • Color
  • Objects
  • Device
  • Variables
  • Functions
  • "Any Component" Blocks
  • 🖥️ App Services & Emulators
  • 🔒App Data Privacy
  • ➕Make Copy
  • 📥Download
  • 📤Share
  • 📱Publish
  • Publish to App Store (iOS)
    • TestFlight Overview
      • TestFlight in Depth
  • Publish to Play Store (Android) with AAB
  • Publish as a Web App
  • Generate Screenshots
  • 🔎Troubleshooting
    • Login Issues
    • FAQs
  • 📏Intro to Spacing
  • 🖼️ Intro to Sizing
  • 🔤Fonts
  • 💾Managing Storage
  • 📝Bugs and Product Feedback
  • Snap to Place Hour of Code Videos
Powered by GitBook
On this page
  • What is a Variable?
  • App, stored and cloud variables
  • App Variables
  • Stored Variables
  • Cloud Variables
  • Initialize a Variable When the App Starts
  • Set a variable during an app event
  • Retrieving a variable
  • Updating when the variable initializes or changes
  • Changing a variable
  • Dynamically named variables

Was this helpful?

Export as PDF

Variables

PreviousDeviceNextFunctions

Last updated 1 year ago

Was this helpful?

What is a Variable?

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.

App, stored and cloud variables

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.

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 similar to saving a value to Local Storage and is especially useful for retrieving a user's previous setting. If you use stored variables, you no longer need to add Local Storage to your app.

You can save any data type as a stored variable.

Cloud Variables

Cloud variables can be used similar to saving and retrieving values to a Realtime DB powered by Firebase and can be used in a number of applications that share data across users in the cloud. If you use cloud variables, you no longer need to add a Realtime DB to your app.

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 Cloudinary Media DB component to upload your audio to the cloud and get a URL that points to it. You can save this URL as a cloud variable.

Initialize a Variable When the App Starts

To create a variable when the app starts, you can grab the block above, select your variable scope (app, stored, cloud) and give the variable a name like hello. 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 like the one above. Simply grab the set variable block and connect it to the value that you want it to be set to.

Retrieving a variable

Once you have stored a value to your variable, you can retrieve it any time using a block like the one above.

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 Firebase DB. This block replaces the Add.Listener and DataChanged blocks in the Realtime DB.

Changing 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. To do so, grab a block like the one above.

Dynamically named variables

The above blocks use hard coded variable names, where you must select a variable from a list of variables that you have initialized.

You can also create dynamically named variables. There are variables that you create and name during app runtime, which do not have an initialize block.

You can name these by typing in a name, or by using other variables to name the dynamically created variables.

You can create dynamically named app, stored or cloud variables.

A cloud variable also works across screens but is saved to the cloud powered by Firebase. By default, the cloud variable is saved to the Thunkable default Firebase database. We recommend saving them to your own private Firebase DB by .

connecting a private Firebase DB to your app