Skip to content

Action: change variable

This action allows you to store data in variables to retrieve and use them later in any button, command, or action. For more information about variables, click here.

The variable must be created beforehand. Then, it should be selected by its name, followed by choosing whether to set (for any data) or increment it (for numbers only).

Set is for assigning a fixed value or data, while increment is for increasing or decreasing the value of a number.

You can save data in the variable either by sending the data directly or dynamically through IDs of previous actions or expressions.

When this button or command is executed, and this action is triggered, the value of the variable will be modified accordingly.

Options of the action:

  • Select variable: Specify the variable to modify and what to store in it.
  • To other user (optional): Modify the variable for another user if the variable to modify is not global. If not specified, it will modify the variable of the user who executed the action.

What does the action return through its ID?

This action does not return anything.


Example

Suppose you have created a command called /change_balance, which increases or decreases the balance of a specified user.

To do this, you need to create two actions inside: Receive parameters, and the one we are currently discussing, Save to variable, both activated.

You enter to configure Save to variable, assuming that the variable for the balance of your bot is balance, you select it to modify, then select Increment.

Finally, you tell it that you want to increase what was passed through the action of Receive parameters, at position 2: #IDAction.param2# (replace IDAction with the ID of the Receive parameters action).

Then, you enter To other user, as you don't want to modify the variable for yourself, but for a specific user, the user ID will also be passed through the Receive parameters action, at position 1: #IDAction.param1# (replace IDAction with the ID of the Receive parameters action).

So, when sending the command /change_balance 123456789 10, it will increase the balance variable of the user with ID 123456789 by 10.

You can also decrease the balance with negative numbers, like /change_balance 123456789 -20.