What are variables in your bot?¶
Variables are a key tool for storing and managing information in your bot. For example, you can save a user's balance or global statistics. Here's how they work and how to use them effectively.
Types of variables¶
-
Private variables:
- Store unique values for each user.
- Example: a user's
balance
-
Global variables:
- Store the same value for all users.
- The name must start with
global_
- Example:
global_discount
-
Native variables:
- Can store either unique values per user or the same for everyone.
- Cannot be created or deleted.
- They come pre-configured with your bots.
- Example: a user’s
username
Types of data variables can store¶
- Text: For names, addresses, emails, etc. (Default: empty
''
). - Numeric: For numbers like balances. The
balance
variable is pre-configured in your bot. (Default:0
). - Date: For storing dates (Default:
01-01-0001
). - Multimedia: For photos, videos, etc. (Default:
{}
). - Forwarded: For storing forwarded messages (Default:
{}
). - Dictionary: For complex structures like
{"name": "Ana", "age": 25}
(Default:{}
).
How to create a variable¶
- Go to
🔑 Manage
→🗃 Variables
→💠 Create variable 💠
. - Choose the type of data the variable will store.
- Enter a name for the variable. If it's global, start with
global_
.
How to delete a variable¶
- Go to
🔑 Manage
→🗃 Variables
→⛔️ Delete variable ⛔️
. - Enter the name of the variable to delete. If it's global, start with
global_
.
What are default values?¶
- Every variable has an initial or default value (e.g.,
0
for numeric variables). - Change the default value with the command
/varsetdefault var_name data
. - This affects future values but won’t change existing ones.
How to use variables¶
Variables can be used in messages, actions, and anywhere expressions are allowed. Variables must always be enclosed in curly braces { }
, as these indicate an expression in VisualMaker.
For example:
Your balance is {balance}.
If the user's balance is 10
, the user will see:
Your balance is 10.
Remember¶
Variables are crucial for customizing each user's experience. Use the provided commands to manage them efficiently and combine them with expressions to create a more interactive and dynamic bot.