How to use enums [ BASICS] -
Kyle - 10.09.2011
Basically in this tutorial, I'm going to show you how to use enums, for example.
If you want to create a small register script insted of having lots of arrays like this:
pawn Код:
new username[MAX_PLAYERS][24];
new password[MAX_PLAYERS][24];
new adminlevel[MAX_PLAYERS];
It will turn to this
pawn Код:
UserStats[playerid][AdminLevel] = 1234;
To start off: you must create the enum:
With pInfo being the name of the enum:
pawn Код:
enum pInfo {
Username[24],
Password[40],
AdminLevel
}
Now you are all set you must create a array which holds the enum:
pawn Код:
new UserStats[MAX_PLAYERS][pInfo];
Then later on you can use the enum as it will work eg:
pawn Код:
UserStats[playerid][AdminLevel] = 1;
That way it gets stored in the enum but still saves time insted of doing a new variable for each.
If you have any questions feel free to ask.
Kyle
Re: How to use enums [ BASICS] -
PrawkC - 10.09.2011
Whats an enumerator ?
Re: How to use enums [ BASICS] -
FireCat - 10.09.2011
Don't you mean
pawn Код:
enum pInfo
{
Username[24],
Password[20],
AdminLevel
}
Very badly explained.
Re: How to use enums [ BASICS] -
Kyle - 10.09.2011
Quote:
Originally Posted by FireCat
Don't you mean
pawn Код:
enum pInfo { Username[24], Password[20], AdminLevel }
Very badly explained.
|
It was a mistake, plus how is it badly explained, I don't see you even trying.
Re: How to use enums [ BASICS] -
Zh3r0 - 10.09.2011
Quote:
Originally Posted by KyleSmith
It was a mistake, plus how is it badly explained, I don't see you even trying.
|
Calm down. Next time when you intend on doing a really good tutorial try harder and at least use the pawn tags or at least the code tags since code sounds funnier but pawn prittier!
Get me? No?
Let me explain detailed. LEARN TO MAKE A TUTORIAL.
Now let's get serious, new comers might see this pretty much confusing, you see.
pawn Код:
Now you are all set you must create a global variable:
new UserStats[MAX_PLAYERS][pInfo];
Sorry but that is not a global variable, yes it's outside any function but it's used only by players with the specified id.
Re: How to use enums [ BASICS] -
[M]onsieur - 10.09.2011
Quote:
Sorry but that is not a global variable, yes it's outside any function but it's used only by players with the specified id.
|
Exactly, and is a array.
Re: How to use enums [ BASICS] -
Kyle - 10.09.2011
Quote:
Originally Posted by Zh3r0
Calm down. Next time when you intend on doing a really good tutorial try harder and at least use the pawn tags or at least the code tags since code sounds funnier but pawn prittier!
Get me? No?
Let me explain detailed. LEARN TO MAKE A TUTORIAL.
Now let's get serious, new comers might see this pretty much confusing, you see.
pawn Код:
Now you are all set you must create a global variable: new UserStats[MAX_PLAYERS][pInfo];
Sorry but that is not a global variable, yes it's outside any function but it's used only by players with the specified id.
|
I see, but I was not sure what to call it as it's like a master of the arrays making it one big array.
Re: How to use enums [ BASICS] -
Zh3r0 - 10.09.2011
Quote:
Originally Posted by KyleSmith
I see, but I was not sure what to call it as it's like a master of the arrays making it one big array.
|
It's a simple 2d array with enums, nothing much to call it otherwise...
3D arrays are dangerous
pawn Код:
new Option[4][MAX_QUESTION][30],
4 options
MAX_QUESTIONS
and 30 is the size of the string, there you go, a 3D array.
Re: How to use enums [ BASICS] -
Lorenc_ - 11.09.2011
How can I use this?
pawn Код:
enum E_EXAMPLE (*= 2)
{
E_EXAMPLE_0 = 1,
E_EXAMPLE_1,
E_EXAMPLE_2
}
An enum is simular to the multi-dimensional array, I'm assuming it's one but anyway. Quoting the wiki here:
Quote:
Enumerations are a very useful system for representing large groups of data and modifying constants quickly. There are a few main uses - replacing large sets of define statements, symbolically representing array slots (these are actually the same thing but they look different) and creating new tags.
|
Re: How to use enums [ BASICS] -
Ehab1911 - 13.09.2011
Bullshit, I didn't understand anything....