[Tutorial] How to use enums [ BASICS]
#1

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:
pawn Код:
enum pInfo {
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
Reply
#2

Whats an enumerator ?
Reply
#3

Don't you mean
pawn Код:
enum pInfo
{
    Username[24],
    Password[20],
    AdminLevel
}
Very badly explained.
Reply
#4

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

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

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

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

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

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.

Reply
#10

Bullshit, I didn't understand anything....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)