Gw Temp

Menu

Tutorial - 'Bank System' by guy

An item about RPG Toolkit posted on

Blurb

A bank system tutorial, you can store items and money and such to the bank account you'll be teached to do.

Body

In this tutorial I will show you how to make a bank account. You can use it to store items or money or something else in it. This program might look hard to some people because it can be quite long and have lots of #if commands and variables in it, but it's not as hard as is looks.

At first the commands I will use in this tutorial:

#mwin()
#mwincls()
#delay()
@
#wait()
#if()
#get()
#getgp()
#takegp()
#branch()
#prompt()
#end()

If there are commands that you don't know, check the help files in RPG-Toolkit.(Help-->RpgCode Command Reference)

To start, make a little conversation where you are asked what you want:

:top
#mwin("What do you want to do?")
#delay(1)
@
#mwin("1 - View account")
#mwin("2 - Withdraw money")
#mwin("3 - Deposit money")
#mwin("4 - Never mind")
#wait(choice!)
#mwincls()

Now you have the part where the player can choose what he wants. Now, we have to make the part that will happen when the player presses 1, 2, 3 or 4:

#if(choice!==1)
{
#mwin("You have money in your account.")
#wait()
#mwincls()
#branch(:top)
}

Somewhere else in the game you have set the account! variable. It probably starts with account!==0 and when you deposit money on it, it will be more. Now let's take a look at the Withdraw money command:

#if(choice!==2)
{
#prompt("How much money do you want to withdraw?", money!)
#if(money!=>account!)
{
#mwin("I'm sorry, you don't have that much money in your account")
#wait()
#mwincls()
#branch(:top)
}
#if(money!<=account!)
{
#givegp(money!)
#account!=account!-money!
#mwin("You withdrew money.")
#wait()
#mwincls()
#branch(:top)
}
}

Now this may be the part where you don't understand it anymore, don't worry, I'll explain. At first, you have to type how much money you want to withdraw. This will be saved in the money! variable. Now, let's say you have 50gp in your account and you want to withdraw 60. This is not possible since you don't have that much (or less). In the sentence #if(money!=>account!) the program checks if you want to withdraw more (>) money then you have. If you want to withdraw more then you have, it goes further in that #if statement. If you have less money, it skips that part and goes to the sentence #if(money!<=account!). This sentence checks if you have less or equal money in your account then you want to withdraw. If this is true, it goes further in that #if statement.

The #givegp(money!) sentence gives you the money that you wanted to withdraw. This shouldn't be to hard to understand, but the next sentence might be. In case we forgot:

account!= the money you have in your account
money! = the money you want to withdraw

So what the sentence #account!=account!-money! does, is subtracts the money you have in your account with the money you want to withdraw. If we would put it in words, it would be like this:

Account we have now! Will become Account we have now! minus the money we withdrew!.

I hope that's clear enough, since I don't know how to explain it better :). Now, we go to the deposit part:

#if(choice!=3)
{
#getgp(gphold!)
#prompt("How much money would you like to deposit?", money!)
#if (money!=>gphold!)
{
#mwin("Sorry, you don't have that much money.")
#wait()
#mwincls()
#branch(:top)
}
#if (money!= {
#takegp(money!)
#account!=account!+money!
#mwin("You have deposited money.")
#wait()
#mwincls()
#branch(:top)
}
}

This is exactly the opposite of the withdraw part. I don't think this should be to hard if you've read the withdraw part carefully. Now the last part:

#if(choice!=4)
{
#end()
}

Easy huh? This just ends the program. Nothing not to understand about it I think.

Here is the complete program:

:top
#mwin("What do you want to do?")
#delay(1)
@
#mwin("1 - View account")
#mwin("2 - Withdraw money")
#mwin("3 - Deposit money")
#mwin("4 - Never mind")
#wait(choice!)
#mwincls()

#if(choice!==1)
{
#mwin("You have money in your account.")
#wait()
#mwincls()
#branch(:top)
}

#if(choice!==2)
{
#prompt("How much money do you want to withdraw?", money!)
#if(money!=>account!)
{
#mwin("I'm sorry, you don't have that much money in your account")
#wait()
#mwincls()
#branch(:top)
}
#if(money!<=account!)
{
#givegp(money!)
#account!=account!-money!
#mwin("You withdrew money.")
#wait()
#mwincls()
#branch(:top)
}
}

#if(choice!=3)
{
#getgp(gphold!)
#prompt("How much money would you like to deposit?", money!)
#if (money!=>gphold!)
{
#mwin("Sorry, you don't have that much money.")
#wait()
#mwincls()
#branch(:top)
}
#if (money!= {
#takegp(money!)
#account!=account!+money!
#mwin("You have deposited money.")
#wait()
#mwincls()
#branch(:top)
}
}

#if(choice!=4)
{
#end()
}