Introduction to Variables Video Tutorial

Learn the basics of variable creation and usage in Landbot. Understand how variables can be created, what are the different types, and the importance of giving each variable a unique name.

In this Landbot tutorial, you'll learn about the importance of variables and how to use them effectively. Variables act as "boxes" that store user responses and enable you to later use that information in your bot's flow.

First, you'll learn about the different variable formats. String variables can hold a wide range of information, from words to hyperlinks to emojis. Number variables are reserved for numeric data, while Date variables are specifically designed to store dates. Finally, Array variables can hold a group of elements of the same data type, like a list of strings or numbers.Next, you'll discover how to create and modify variables within the Landbot builder. When building your bot's flow, you'll want to create a unique variable for each question block. This will help you store and retrieve user responses accurately.

You'll also see a demonstration of how to create a question name block and a question email block with their corresponding variables. You'll learn how to change variable names and create unique names for each block.

Finally, you'll see why it's essential to give each variable a unique name. If you reuse the same variable name, the information stored in the variable will overwrite itself, and you'll lose data. You'll see a demonstration of how this can happen with a button block that uses the same variable for two different questions.

In conclusion, variables are essential components of any Landbot bot. With the knowledge gained from this tutorial, you'll be able to create effective variables, store user responses accurately, and use that information to create more human-like conversations.

00:00 Intro

00:47 Variable formats

01:32 How to create variables

02:02 Quick Example

03:11 Unique names to variables

04:28 Recap

Every time you ask a question in the bot and want to save that answer, you have to store it in a variable.Think of a variable as if it was like a "box" that you can give a name and store "things" inside.In this case, those "things" are values you give to that variable.In Landbot, all variables start with an @symbol.

For example, if you have a question text block that asks the user for his favorite colour, and you want to save the answer to later use, for example in the flow, you have to create a variable associated to that question block. So, we will divide the video in 4 sections: First, the different formats that variables can beSecondly, where and how you can create your variablesThen, a simple use case on how variables can be usedAnd lastly, the importance of giving each variable a unique name.

So, starting this off, the different formats are: String: This is the most flexible type of variable. It is usually used to save a string of characters inside it, these characters can be words, sentences, numbers, dates, signs, emojis, hyperlinks, etc. The next one is Number: here you can ONLY store numbers. Use this type if you need to perform math operations later on.Date: to save dates inside these variables, in the most common Date FormatsAnd Array:  An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, like a String or Number. An array variable is very handy if you are a developer or if you want to try out more of our technical features and workarounds.

Let’s now pass on to where and how you can create variables in your builder:Usually we will create variables to the question blocks we have in the flow, since for us it’s important to store what the user is saying. Each question should be associated with a unique variable. As you can see here the question name block will store the name in the variable @name, the email block in the @email variable and this buttons block asking for the avg user’s budget, int the @budget variable. It should be like this for all the question blocks whose information you want to save.Let me show you a quick example,Let’s create a question name block, associated with the variable @name, continue that block by adding a question email block, with the variable @email.

As you can see, both block’s automatically create the variable for us, other blocks like the buttons block or the question number block don’t do that, so remember to create a variable if you intend to save that answer. If you don’t like the name of the variable displayed you can easily change it by typing and creating a new one. So, after these three blocks, create a message block saying “Hi @name, is @email your email? and are you really @age years old?”. Normally we would continue building the bot, but just for now we'll leave it like this and keep it simple.

Press save, go to share and preview it, ok here I’ll type my name “nik”, now for my email i will write “nik@test.com” and for the age i’ll say 55. And as you can see the bot has used the variables to write the message with my name, email and age I just selected. This technique is commonly used as you get closer to the user and achieve a more human like conversation. Cool! Now, let’s see why it is important to give unique names to your variables:

For example, if we create a buttons block with the variable “options'', and we follow the block with a different buttons block but the same variable associated with it, the variables would overwrites and Landbot would only save the last one, that's why you should give them unique names such as @options1 and @options2.To show you this, let’s start  by creating a first buttons block asking what burger they want with buttons like “chicken” and “beef”, now create the variable “@options”, lead the default path to a new buttons block, in which we will ask for a drink, where our options will be “Pepsi” and “Coca Cola”, now choose the variable @options too. And lastly add a message block with the message “Is @options correct?” press save.

And let’s see how the bot behaves.

So here, let’s select “chicken”, and here “CocaCola”, and as we can see, the bot is giving us the last value of the variable @options, in this case CocaCola, meaning that the bot wasn’t able to save the first option we chose, that’s because as we mentioned before, both question blocks save the information under the same variable, and the variable overwrites itself with the new information. And that’s why you need to create variables with unique names in order to save the answers you want to later use.

Awesome, we’ve rounded up everything, so let’s recap: First we saw, the different formats that variables can beSecondly, where you can create and modify your variables. Then, a simple use case of how variables can be usedAnd lastly, the importance of giving each variable a unique name. So that’s it, see you in the next one!

Key takeaways

  • Types of variables
  • How to create a variable
  • Types of variables
How to create a variable