Howdy! Your friend Despain here, with another RPG Maker VX Ace tutorial. Today, we’re going to be using variables and conditional branches to create a simple bank event. The player will be able to check his current balance, or deposit or withdraw money. A banking system like this can add depth to your game, especially if you want to encourage your player to manage his finances.
This is what the event will look like when we are done with it:
This event is going to use three variables. You can create them with the Control Variables event command, under the Game Progression category on the first page of event commands.
Clicking the […] button will bring up the Variable list. Create three new variables.
The first thing that we should do is set the Gold in Hand variable to be equal to the player’s current gold in his inventory. We put this at the beginning of the event so that the variable will update every time the player begins a conversation with the banker.
Use the Control Variables command, and set the Gold in Hand variable to be equal to the player’s current gold. You can find it in the Game Data section.
You might also want to set the Deposit/Withdraw variable to the number 0. This command isn’t necessary for the event to function properly, but it will make things more convenient for the player. I’ll explain this when we get to the part where we use the Input Number command. For now, just trust me. 🙂
Before we do anything with the other variable, we’ll use the Show Choices event command to give the player the chance to choose how to interact with his banker. This command can be found on the first page of the event commands, under the Message category.
This will create a number of branches. Your event should look something like this:
For the rest of the event, we will be working within the branches created by the Show Choices command. Let’s get the easy ones out of the way first. You can leave the [Nothing] branch blank if you want—in my example, there’s a simple “come again” message there.
The [Balance] branch will make use of the Gold in Bank variable, even though we aren’t going to be modifying the variable. We simply want to display the current value of the variable, so the player can use this option to check how much money he has in the bank.
We use the control character \v[X] to display the value of the variable within a message box.
Control characters are super useful. The \v[X] character will display the value of the variable X in the message box. In this example, the Gold in Bank variable is the variable with the ID 1, so we write \v in the message box (in my example, I’ve written 01, out of personal habit—1, 01, 001, all work just fine).
You’ll also notice that I’ve used the control character \c[X] in this message box. That changes the color of the text. I’ve placed it around the \v Gold text to change the color of those words, which creates emphasis for the player. That is optional—I’m a fan of changing text colors for words that the player should pay attention to.
If you preview the text, it should look something like this:
You’ll see the \v[X] control character represented as a zero in the preview. That means it’s working.
So now the player can check the balance in his bank account. The next step is to use the Input Number command to allow him to change that balance by depositing or withdrawing money.
Let’s work in the [Deposit] branch first.
Select the Input Number event command—it’s on the first page of the event commands, under the Message category.
This command will allow the player to input a number, and the command will store that number into a variable. Select our Deposit/Withdraw variable. The player will now be able to set the value of that variable to any number he likes.
Remember before when I said that we should reset this variable to 0 at the beginning of the event? This is so that the default value is 0 when the player enters the number. If we don’t reset it to 0, the default value will be the same amount of money that the player input last time he used the bank. It doesn’t change the functionality of the event, but it prevents the player from having to mess around with the numbers—this way, whenever he goes to deposit money, he starts with zero and chooses the amount, instead of changing the amount from whatever he deposited last time.
In order to make sure that the player doesn’t deposit more money than he has in his wallet, we’ll create a conditional branch. You can find the Conditional Branch command under the Flow Control category on the first page of the event commands.
We have to compare the player’s current gold to the amount of money that he has chosen to deposit. Check if the Gold on Hand variable is less than the Deposit/Withdraw variable. Make sure that the “Set handling when conditions to not apply” box is checked.
Your event should look something like this:
Now, we can work within the branches created by the conditional branch. The conditional branch says “if the player’s current gold is less than the amount that he wants to deposit“. If that is true—which means that the player does not have enough gold to deposit—then we’ll prevent him from doing so. A simple message box under the conditional branch will be enough.
The Else branch will happen if the player does have enough gold—if he has more gold than he’s chosen to deposit. So that is where we will modify some variables. The first thing that we want to do is remove the gold from the player’s inventory. You can find the Change Gold event command under the Party category on the first page of the event commands.
You’ll want to decrease the player’s gold by the amount that he has chosen to deposit. For the “operand”, select the Deposit/Withdraw variable.
That money is going into the bank. So use the Control Variables event command to Add the Deposit/Withdraw variable to the Gold in Bank variable. Make sure to set the “Operation” to Add instead of Set, so the gold is added to the player’s balance rather than overwriting it.
If you want, you can add other effects. In my example, I’ve added a sound effect and some wait commands, and a message box that confirms the transaction. My event looks like this, and yours should be similar:
Now the player will be able to deposit his money into the bank account. The last thing that we need to create is the option for the player to withdraw money. Let’s move onto the [Withdraw] branch. We will use the same commands what we use in the [Deposit] branch.
Start off with an Input Number command. You can use the same Deposit/Withdraw variable, because we reset it to 0 at the beginning of the event every time it runs.
When we create our Conditional Branch, we want to check the value of the Gold in Bank variable, rather than the gold in the player’s inventory. The player cannot withdraw more money than he has in the bank.
If the variable Gold in Bank is less than the Deposit/Withdraw variable, the player cannot proceed, so her gets a message. If it is more (under the Else branch), we need to change some variables. Just like we did in the [Deposit] branch above. This time, instead of adding to the Gold in Bank variable, we subtract from it.
By subtracting the Deposit/Withdraw variable from the total of the Gold in Bank variable, the player removes that much money from his balance. Adding that money back to the player’s wallet is simple: use the Change Gold command just like we used it before, expect with increase instead of decrease. We increase the player’s current gold by the amount he has chosen in the Deposit/Withdraw variable.
Now your event should look like this:
Recognize it? That’s the same image from the beginning of the tutorial. Congratulations, we’re done!
This is a base for the bank event—you can do a lot more with it. For example, your bank might reward the player with items if he has deposited a lot of gold, or the bank might add interest to the player’s balance if he stores money with them for a long period of time. There are lots of ways to add onto this event, so don’t be afraid to experiment and explore!
Thanks for reading—I hope you learned something from this tutorial. Leave a comment here and let me know what you think, and feel free to leave suggestions for my next tutorial. Until then, happy game making. 🙂