Skip to content

Action: Change variable

This action allows you to store, modify, or update values in previously created variables. You can use variables to store and modify information such as balances, user data, responses, and more. More information about variables here.


What can you do with this action?

  • Set values: Assign a fixed value to a variable.
  • Increase values: Increase or decrease the value of a numerical variable.
  • Store data dynamically: Use values from other actions, such as the result of a query or a captured parameter, to set or increment the variable.
  • Modify variables of other users: Change variables for a specific user, such as assigning points, balance, or any other data.

How to configure the action?

1. Create the action

  1. Go to your bot and click 🛠 Edit to enter edit mode.
  2. Select the button or command where you want to add the action, or create a new one.
  3. Click Actions 🌟🎯 New action🗃 Change variable.
  4. Click Configure 🛠 to set up this action.

2. Configure the options

➡️ Select variable

  • Choose the variable you want to modify. Variables must be previously created in the bot. More information here.
  • Modification type:
    • Set: Assign a specific value (can be text, number, date, etc.).
    • Increment: Add or subtract from the current value of the variable (only for numeric or dictionary-type variables).

➡️ To other user (optional)

  • If you want to change the variable of a user different from the one executing the action, specify their @username or their user ID.
  • If nothing is selected, the modified variable will belong to the user who executed the action.

3. Activate the action

Click ✅ Activate to activate this action and make it functional.


What does this action return through its ID?

This action does not return any value.


Practical example: Modify a user's balance

Suppose you want to create a /add_balance command to adjust a user’s balance. This command requires two parameters:

  1. @username of the user: To identify who will receive the balance change.
  2. Amount to modify: To increase or decrease the balance.

An example command usage would be:

/add_balance "@JohnDoe" 5

1. Create the command

  1. Enter editor mode by clicking 🛠 Edit on your bot.
  2. Create a new command by clicking ✳️ New button | command and naming it /add_balance.
  3. Click Hide 👁 so only the bot owner (you) and administrators designated by you can use it.
  4. Go to Actions 🌟 to configure the command.

2. Configure the actions

a) Action 1: Receive parameters
  1. Click 🎯 New action🖥 Receive parameters.
  2. This action does not require configuration, simply activate it by clicking ✅ Activate.
  3. Copy the ID of this action, as you will need it shortly.
b) Action 2: Change variable
  1. Click 🎯 New action🗃 Change variable.
  2. Click Configure 🛠 and set up the following:

    • Select variable: Enter the name of the variable you want to modify (e.g., balance).
    • Modification type: Select 🔺 Increment 🔺.
    • Value to store: Specify the value to add or subtract using the second captured parameter:

      {#ActionID.param2#}
      

      Replace ActionID with the Action ID of Receive parameters.

    • To another user: Indicate the user whose variable will be modified using the first captured parameter:

      {#ActionID.param1#}
      

      Replace ActionID with the Action ID of Receive parameters.

  3. Return to the actions menu and activate the action by clicking ✅ Activate.

c) Action 3: Send message
  1. Click 🎯 New action✉️ Send message.
  2. Click Configure 🛠💬 Set message 💬 and enter a confirmation message for yourself:

    ✅ Balance successfully updated.
    
    User: {#ActionID.param1#}
    Change made: {#ActionID.param2#}
    

    Replace ActionID with the Action ID of Receive parameters.

  3. Return to the actions menu and activate the action by clicking ✅ Activate.


Final result

When you send the command /add_balance "@JohnDoe" 50, the bot will do the following:

  1. Capture the data:

    • "@JohnDoe" (parameter 1): The @username of the user (text, enclosed in quotes).
    • 50 (parameter 2): The amount to modify (a number, not enclosed in quotes).
  2. Increase the balance variable of the user identified with the username @JohnDoe by 50.

  3. Confirm the operation by sending you a message like:
    ✅ Balance successfully updated.
    
    User: @JohnDoe
    Change made: 50
    

This is how the actions turned out

VisualMaker action change variable example


Useful notes

  • To decrease the balance, use a negative number:

    /add_balance "@JohnDoe" -20
    
  • If you use the ID of the user instead of a @username, it will also work:

    /add_balance 123456789 3
    
  • This action is ideal for managing points, balances, wallets, or any system based on dynamic values.