Posts: 107
Threads: 21
Joined: Jun 2011
Reputation:
0
1) Is it possible to start an array from 1 instead of 0?
2) How to reset a variable? By that I mean, if the old variable had "1234" as a password, then in-game if I change it to something else then I can still use 1234 and the new password. I want the old password to be removed, by resetting what is inside the variable, how to do it?
Thanks for reading.
Posts: 6,129
Threads: 36
Joined: Jan 2009
1) You can't alter the ways arrays process, but you can add +1 to the size of one of your dimensions for your array, and avoid using 0. For example:
pawn Code:
new E_PLAYERS[MAX_PLAYERS+1];
E_PLAYERS[1] = 42; // (or 0+1 instead of 1)
This isn't wise though, because you'll be wasting at least 4 bytes of memory for every item in your array. (I'm generally referring to use of this with an enum, but even if not - you're still wasting 4 bytes for just a single dimension.)
2) If you want to reset the value of an integer, you can always just set its value to 0. When you create an integer, the default value for it is 0. For strings, you can use
strdel, set the value of your string to nothing with format or insert a null character for cell 0.
Posts: 107
Threads: 21
Joined: Jun 2011
Reputation:
0
Alright, thank you Calg00ne.
But then won't the password work if I type 0 then? It probably would but I could add a lenght check.
Thank you.
Posts: 6,129
Threads: 36
Joined: Jan 2009
If you're smart and don't use udb_hash, then you'll be using a string for passwords, so see:
Quote:
For strings, you can use strdel, set the value of your string to nothing with format or insert a null character for cell 0.
|
Otherwise, even with udb_hash - I presume setting the password to 0 would be fine.
Posts: 6,129
Threads: 36
Joined: Jan 2009
Passwords generally have to match, so as long as you don't allow people to insert 0 in to your password field when you reset the password, you'll be fine, otherwise they'll be able to use the password 0 even if you just cleared it.
Reputation ponts can only be given by someone who already has reputation points - but thanks, it's the thought that counts.