Questions
#1

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.
Reply
#2

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.
Reply
#3

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.
Reply
#4

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.
Reply
#5

I know.

But the passwords are not for user data. It's for something else I have in mind.

Anyway thank you again.

I gave you some reputation.

EDIT: Your reputation counter didn't raise, wierd.
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)