ID:2232790
 
Hey guys... I was making a banking system for my game... and I got everything coded good... the code works, But I'm using the bank account as a variable under the mob... I think my problem is that when I select the account, the variable becomes both "Chequings Account" and "Savings Account and randomly picks one of the two...

The code works, but the bug is that it doesn't always pick the right bank account.

Code:
mob/Banker
icon = 'Banker.dmi'
mob
var



SavingsAccount = 0 //This is the players Savings Account
ChequingsAccount = 0 // And Chequings Account
Interest = 0 //This hasn't been applied yet
LineOfCredit = 500 //This is the Line of Credit stored as a player variable
AccountChoice //This is the Account Choice from SelectAccount()




mob/Banker

verb
UseBank()
set src in view()
var/l = (input("Welcome, What kind of banking would you like to do today?") in list("Withdraw Money", "Deposit Money", "Check Balance", "Exit"))

if (l == "Withdraw Money")
WithdrawMoney()
else if (l == "Deposit Money") //I didn't include the Deposit Money in the problem help because it's the same problem
DepositMoney()
else if (l == "Check Balance")
CheckBalance()
else if (l == "Exit")
return




proc
SelectAccount()
set src in view()
switch (alert("What account would you like to use today?", "Account Selection", "Chequings Account", "Savings Account", "Line of Credit"))
if ("Chequings Account")
usr.AccountChoice = usr.ChequingsAccount
if ("Savings Account")
usr.AccountChoice = usr.SavingsAccount
else if ("Line of Credit")
usr.AccountChoice = usr.LineOfCredit




proc
//Use_Bank()
WithdrawMoney()
set src in view()
SelectAccount()
var/s = (input("How Much Would You Like to Withdraw Today") as num)
if (usr.AccountChoice == usr.ChequingsAccount)
if (usr.ChequingsAccount >= s)
usr.ChequingsAccount -= s
usr.Money += s
usr << "You withdraw $[s] from your Chequings Account leaving you with a balance of $[usr.ChequingsAccount]"
usr.AccountChoice = ""

else usr << "Sorry, You Don't have enough in your Chequings Account... Your Current Balance is $[usr.ChequingsAccount]"


else if (usr.AccountChoice == usr.SavingsAccount)
if (usr.SavingsAccount >= s)
usr.SavingsAccount -= s
usr.Money += s
usr << "You withdraw $[s] from your Savings Account leaving you with a balance of $[usr.SavingsAccount]"
usr.AccountChoice = ""

else usr << "Sorry, You Don't have enough in your Savings Account... Your Current Balance is $[usr.SavingsAccount]"


else if (usr.AccountChoice == usr.LineOfCredit)
if (usr.LineOfCredit >= s)
usr.LineOfCredit -= s
usr.Money += s
usr << "You withdraw $[s] from your Line of Credit... You currently have a limit of $[usr.LineOfCredit] remaining in your balance"
usr.AccountChoice = ""

else usr << "Sorry... You don't have enough on your Line of Credit to make that transaction"


Problem description: I think the problem is that the AccountChoice variable is Equal to both Chequings Account and Savings Account or Line of Credit... The problem with this code is that it sometimes registers as Savings Account for Line of Credit and registers and Chequings Account for Savings, etc.... Besides that everything works.

You're checking if usr.AccountChoice, which is equal to string like "LineOfCredit" is equal to the actual values inside the mob's vars, usr.LineOfCredit, e.t.c.

What you need is
if(usr.AccountChoice == "ChequingsAccount")


e.t.c.
I tried your advice instead of

if (usr.AccountChoice == usr.ChequingsAccount)


I did:

if (usr.AccountChoice == ChequingsAccount)


I had the same problem... I withdrew from the Savings Account and it took the money out of my Chequings Account.

**Note**

usr.ChequingsAccount // is a variable that keep track of how much money is in it.

//So is:

usr.SavingsAccount and usr.LineOfCredit

//They're all variables that keep track of money.

usr.AccountChoice // is a variable that saves the information of what account is used.
Well... You thought my var AccountChoice was a string, and I tested it out as a string, and it works perfectly that way... My problem was the fact I made a variable equal to a variable... I tried the string out and there's no problems that way. The Chequings account is equal to the Chequings account and the Savings Account is equal to the Savings Account... Thanks for giving me the idea to use a string instead of another variable.
Ah, i misread your code last night. Apologies, running on very little sleep.

The problem is in your switch you're setting it to your bank variables, but the program actually sees that as being set to the VALUE in the variable.

So if Savings Account and Checking Account have a balance of 2 they'll look the exact same in Account Choice.

In Select Account () set Account Choice to strings of the bank accounts, and check for that later.
Unfortunately on my phone so sorry for formatting and lack of code.

mob/Banker
icon = 'Banker.dmi'
mob
var



SavingsAccount = 0 //This is the players Savings Account
ChequingsAccount = 0 // And Chequings Account
Interest = 0 //This hasn't been applied yet
LineOfCredit = 500 //This is the Line of Credit stored as a player variable
AccountChoice //This is the Account Choice from SelectAccount()




mob/Banker

verb
UseBank()
set src in view()
var/l = (input("Welcome, What kind of banking would you like to do today?") in list("Withdraw Money", "Deposit Money", "Check Balance", "Exit"))

if (l == "Withdraw Money")
WithdrawMoney()
else if (l == "Deposit Money") //I didn't include the Deposit Money in the problem help because it's the same problem
DepositMoney()
else if (l == "Check Balance")
CheckBalance()
else if (l == "Exit")
return


proc
//Use_Bank()
WithdrawMoney()
set src in view()
var/AccountChoice=alert("What account would you like to use today?", "Account Selection", "Chequings Account", "Savings Account", "Line of Credit")
var/s = (input("How Much Would You Like to Withdraw Today") as num)
s = max(0,round(s)) // This is to ensure they withdraw a round number, and don't try to withdraw a negative.
if (AccountChoice == "Chequings Account")
if (usr.ChequingsAccount >= s)
usr.ChequingsAccount -= s
usr.Money += s
usr << "You withdraw $[s] from your Chequings Account leaving you with a balance of $[usr.ChequingsAccount]"

else usr << "Sorry, You Don't have enough in your Chequings Account... Your Current Balance is $[usr.ChequingsAccount]"


else if (AccountChoice == "Savings Account")
if (usr.SavingsAccount >= s)
usr.SavingsAccount -= s
usr.Money += s
usr << "You withdraw $[s] from your Savings Account leaving you with a balance of $[usr.SavingsAccount]"

else usr << "Sorry, You Don't have enough in your Savings Account... Your Current Balance is $[usr.SavingsAccount]"


else if (AccountChoice == "Line Of Credit")
if (usr.LineOfCredit >= s)
usr.LineOfCredit -= s
usr.Money += s
usr << "You withdraw $[s] from your Line of Credit... You currently have a limit of $[usr.LineOfCredit] remaining in your balance"

else usr << "Sorry... You don't have enough on your Line of Credit to make that transaction"


Of course an Associative List like:
list/bankAccounts = list("Checkings Account" = 0, "Savings Account" = 0, "LineOfCredit Account" = 0)

would work even smoother, but no need to stress about that now.