Skip to main content

Working with Variables in Expressions

This tutorial will tell you about the most common practices of using variables in expressions, as well as provide step-by-step guide on how to create functionality using them. You can learn about what variables are, what principles and mechanics underlying the work with them in the Manual on Variables.

The method of presenting information in this manual assumes that you have already familiarized yourself with the documents indicated by the links and, in general, understand the principles of the described functionality.

 

❖ Required functionality

 

Additional variables.
To connect, go in your bot:
☞ 🔐Admin | 🧩Expressions | 📂Variables

Macros and expressions in buttons.
To connect, go in your bot:
☞ 🔐Admin | 🧩Expressions | 📂Buttons

Conditions.
To connect, go in your bot:
☞ 🔐Admin | 🧩Expressions | 📂Buttons

Package of additional "Tokens of Functions".
To connect, go in your bot:
☞ 🔐Admin | 🧩Expressions | 📂Actions

IMPORTANT: The purchase of functionality for the bot is available only to the Creator (owner) of the bot. Admins CANNOT buy functionality!

 

❖ Working with variables in expressions

 

The convenience of using expressions in Bonus buttons, Exchange buttons, directly in messages and especially in Actions lies in the fact that it makes it possible to perform all the necessary calculations and assign all the necessary values ​​by one user click of the button.

 

How to zero out a variable:

{-1 * %balance%}

If you add this expression to the Bonus, Exchange, or Action buttons, it sets the variable to zero. Although Actions are already able to set the desired value, it is not necessary to use an expression for this.

 

How to set a specific value by deleting the old one:

{-1 * %balance% + 5}

Zero the value of the variable and add 5. Use if you need to set a specific value in the variable using the button. Although Actions are already able to set the desired value, it is not necessary to use an expression for this.

 

How to compare a text variable:

{"%answer%" == "Ответ"}

{"%answer%" == "👍"}

All text variables in expressions must be "quoted".

Emoji can also be compared.
It can be used to check a password or a code word from a video task for a match.

 

How to add a percentage to a variable:

In a bot, an expression of this type DOES NOT work:
{%variable% + 10%}
Instead, you need to carry out the calculation in the expression itself:
{%variable% + ((%variable% / 100) * 10)}
A shorthand version of the record:
{%variable% + %variable% * 0.1}

And the shortest notation for adding a percentage:

{%variable% * 1.1}

The result of all the above expressions will be 10% change.

Examples of numbers and percentages:
* 1.1 is + 10%
* 1.15 is + 15%
* 1.25 is + 25%
* 1.5 is + 50%
* 2 is + 100%
* 2.5 is + 150%
And so on...