Set a Variable Block Video Tutorial

Learn how to set variables, what they're used for and what can be done

In programming, a variable is an essential tool that allows us to store and manipulate data during the execution of a program. The Set Variable block is a crucial tool that allows us to create, establish a format, and set a value to a variable.

The Set Variable block is a useful tool that can help us store and manipulate data effectively. It allows us to name and store values such as numbers, texts, and dates in a box-like structure that we can access and manipulate later on.

Creating a Set Variable block is simple. We can choose to set or unset a value to a variable, and then create or choose an existing variable to store the value. We then select the format of the variable, which can be text, number, date, or array, and then set the value of the variable.

The Set Variable block also offers the option to perform calculations on the value. For example, we can add, subtract, multiply, divide, or calculate the remainder of two numbers. Dates can also be added or subtracted. This feature can be especially useful when working with complex data sets.The Set Variable block provides two outputs: success and failed. If the input is correct, the flow will follow the green path, but if the input is incorrect, the flow will follow the red path.

In summary, the Set Variable block is a useful tool for storing and manipulating data during program execution. It allows us to create, establish a format, and set a value to a variable. By providing the option to perform calculations on the value, it makes it easier to work with complex data sets.

00:00 Intro

00:08 Sections

00:23 What's a variable

00:43 Anatomy of the block

01:36 Calculations

2:22 Recap

The set-a-variable block allows us to create, establish a format, and set a value to a variable.

This video will be structured into 2 parts:
First of all, we will see how to set up variables and I’ll show you how useful they can be.

And secondly, we will see the set variable block in-depth and its settings.


What is the Set Variable block and what is it used for?
So, What’s a variable you might be asking? Think of it as a box that we can name and start storing different “things”, “things” being values as numbers, texts, dates, etc...


For Example, a price that might be changing through the course of the flow. These changes are stored in the variable named Price and will be updated during our flow to have a final price when the flow ends.

So, let’s create a set variable block right here after our first block, the first thing we see is the switch mode option, where the options are set or unset a value to a variable. The set option will let us add a new value to a variable while the unset option will assign an empty value to an already existing variable, both options when the flow goes through the block. But let’s keep it in the set mode for this example.

We can use an already created variable or create a new one, just type the name of this new variable. Oh! and keep in mind, no spaces are allowed!

Now comes the time to select the type format of the variable, this is the type of information the variable will store.

We have four options:

-Text: think of it as a STRING of characters
-Number
-Date
-And Array: which stores a collection of variables that are the same type or JSON objects.

After we have selected the format of our variable, choose its value by writing it in the text box, if we do not plan on giving it a fixed value we can also make it depend on other variables’ values.


The variable block gives us the option to choose if we want our value to perform a calculation, keep in mind that only Numbers and dates can do that.

For numbers, the available operations are:
- Addition (+): To Sum
- Subtraction (-): To Subtract
- Multiplication (*): to Multiply
- Division (/). To Divide
- And Modulus "remainder" (%)
For dates, we only get the option to add or subtract.

And just a quick tip, we can do the same calculations and much more with the Formulas block.

Finally, after we’ve done all of this, our block will be set and ready to use, and we will get two different outputs:

Success
and Failed

If the client writes the input correctly the flow will follow a Green path, BUT if he inserts anything that isn’t in the correct format of the variable, the flow will go through the Red path and continue accordingly.

So let’s recap everything we went through:
First, we understood what was the Variable block and what we could do with it
And then, we explored the deeper setting that variables come with.

So, that’s all, see you in the next one!

Key takeaways

  • Block anatomy
  • What is a variable
  • How to use them correctly
  • This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.

Please note that 'Variables' are now called 'Fields' in Landbot's platform.