Skip to content

How to Change a User's Balance?ΒΆ

Let's say in our bot we have a button called Claim, and we want it to increase the user's balance by 1 when clicked.

The button would look like this:

Change User's Balance in VisualMaker

Here's how it works: every time a user clicks the button, their balance variable will increase by 1, and then we'll show them a message telling them that their balance has increased by 1, along with their total balance.

Keep in mind

Before we begin, it's important to mention that we need to have the variable to be modified created beforehand. The balance variable comes pre-created with your bot by default. However, if you're going to modify a variable other than balance, you'll need to create it. We recommend reading the section dedicated to variables by clicking here before proceeding.

Let's see step by step how to increase the balance variable:ΒΆ

  1. First, enter your bot's editor mode by clicking the πŸ›  Edit button, and click the button you want to edit, in our case, it's Claim. Then click on Actions 🌟 to edit its actions.
  2. Add the Save to variable action. This action is very important and you'll use it often, as it's responsible for saving and changing data in previously created variables.
  3. Click on Configure πŸ›  to set up the action.
  4. Click on πŸ’  Select variable πŸ’  and send the name of the variable to modify, in our case, it's balance.

    VisualMaker selecting variable

  5. Now you can choose between πŸ’’ Set πŸ’’ and πŸ”Ί Increment πŸ”Ί. Let's see the difference between each one:

    • Set: used to set a fixed value in a variable, whether it's a number in a numeric variable, text in a text variable, or a date in a date variable, etc.
    • Increment: exclusive to numeric variables, it's used to increase or decrease the value of a numeric variable.

    In our case, as you might have guessed, we need to increment the balance. Therefore, click on πŸ”Ί Increment πŸ”Ί.

  6. Now we need to specify the amount to increment. We've said we want to increase the balance variable by 1, so simply send 1.

    This way, when the button is clicked, the balance variable of the user who clicked the button will increase by 1. If we want to decrease it, we just need to put a negative number, like -1.

    We could also increment the variable not for the user who clicked the button, but for another user of the bot. For that, we have another button that has just appeared called πŸ‘€ To other user πŸ‘€. It's not necessary in this guide, but it's worth mentioning.

  7. Go back to the button's actions list and create a new one, this time it will be a Send message action, so we can send a message to the user telling them that their balance has changed, and click on Configure πŸ›  to set it up.

  8. Save the message that will be sent to the user when they click the button, after their balance has been changed. In my case, I'll use the following:

    VisualMaker sending message

    Note that I've used an expression to show the value stored in the variable to the user. It's as simple as writing the variable's name in curly braces. In our case, the variable is named balance, so the expression to display its value in a message would be {balance}.

  9. Go back and activate both actions.

And that's it! When the Claim button is clicked, the balance will increase by 1, and we'll show it to the user, it will look like this:

Change User's Balance in VisualMaker

As you can see, I clicked the button 2 times, and it works!