mob/var
PIN_Number
mob/verb
New_PIN()
if(!PIN_Number)
var/a = input("Please enter a four digit number to be used as your PIN number.","New PIN") as null|num
if(!a)
alert("Canceled...","New PIN")
return
if(length("[a]")<4 || length("[a]")>4)
alert("Your PIN number must 4 digits in length.\nProcess canceled.","ERROR")
return
PIN_Number = a
alert("PIN number successfully assigned.","New PIN - Sucess!")
else if(PIN_Number)
var/b = input("For security, please enter your current PIN number.","Security") as null|num
if(!b)
alert("Cenceled...","Security")
return
if(b == PIN_Number)
var/c = input("Now please enter the new PIN you would like to use.","New PIN") as null|num
if(!c)
alert("Canceled...","New PIN")
return
if(length("[c]")<4 || length("[c]")>4)
alert("Your PIN number must 4 digits in length.\nProcess canceled.","ERROR")
return
PIN_Number = c
alert("PIN number successfully changed.","New PIN - Success!")
else
alert("Incorrect PIN number.","ERROR")
return
Unlock()
var/a = input("Please enter your PIN number","Unlock") as null|num
if(!a)
alert("Cenceled...","Unlock")
return
if(a == PIN_Number) alert("You have successfully entered your PIN number.","Unlock - Success!")
else alert("Incorrect PIN number.","ERROR")
ID:272807
Mar 8 2009, 6:32 am
|
|
Here's my thought process of how to do a PIN number for accessing bank accounts in-game and whatnot, but I just can't help but think that there's a better way :\ Is there? Or have I pretty much got the best way of doing such a thing?
|
In response to GhostAnime
|
|
I like having specific conditions in my programming, and "else if()" settles that. Is there really ant significant difference or reason I should use "else" instead?
if(length("[a]") != 4) Thanks for that one though, I totally forgot I could do that haha. |
In response to GhostAnime
|
|
I just thought of this. >_>
Would it be better to use a list var defined under a Banker mob to hold peoples' keys with their associated PIN numbers? I forgot to describe the purpose of the PIN number system above haha xD mob/Banker |
In response to Spunky_Girl
|
|
Spunky_Girl wrote:
Is there really ant significant difference or reason I should use "else" instead? This should be obvious; if you use 'else' the code under it will run on the condition that the previous if() <small>(and else-ifs when applicable)</small> didn't pass their condition (and so didn't execute), but if you use else-if then in addition to checking the if()s before it, it checks an additional condition - and the condition you're checking is very superfluous because the fact it's true is already established - since that part of the code wouldn't execute if it isn't. if(MyCondition) |
In response to Spunky_Girl
|
|
Spunky_Girl wrote:
Would it be better to use a list var defined under a Banker mob to hold peoples' keys with their associated PIN numbers? By assumption, probably not. Is there any reason the Banker mob needs to store the PINs locally? Are players meant to possibly have different/separate PINs per every Banker mob? Is there any reason to separate this data (also making saving it extra work)? You could as well use a global [associative] list(s) to store any var you use that belong to something - but in an object-oriented language, you don't have to. I forgot to describe the purpose of the PIN number system above haha xD Yes, I believe you did... ;P |
In response to Kaioken
|
|
Ah, I didn't think of that haha. I'll just stick with my original way then xD
|
You don't even have to check the length of a string in this case, but could simply check if the number is in a range of values.
And you could make use of modular programming ;) mob I included three tries, followed by a lock for confirming your PIN, just for the fun of it. |
In response to Schnitzelnagler
|
|
Like I said, it was just a thought process that I had tested to see if it would actually work, and it did. I just wanted to see if there was a different/better way of doing such a thing.
By the time you had posted, I had already made it more modular ^-^ But thanks for the decimal insight; I had totally forgotten about decimals >.< One thing I did notice, was that you did 1000 to 9999. Bad, because what if the person would want to use 0000 as their PIN number? Actually, would 0000 even return anything? I'd have to text embed it is my guess, so that it does return what I want, then use text2num() or something. EDIT I also spotted a bug in your "retry" system you have set yup there. If a player were to click on the verb before hitting that 3 limit every time, then they could get passed it, and never hit a locked PIN number :\ |
You can make "else if(PIN_Number)" to just "else" since the first if() checks if it is FALSE.
But other then those minor things, that's pretty much the same I would do.