2d array
Is it possible to create a 2d array, with the following:

pawn Код:
`new var[] = {    var1 = 3,    var2 = 5};`
I want to use it like
if( ### == var[var1] ) { }

~Wesley
Thats not a 2D array

2D means new a[][]

And a 2D array is declared like this
Код:
```new a[][]  =
{
{1,2,3,4,5},{6,7,8,9,10}
};```
and when you refer a[1][1] you get 7

in your case you are supposed to do
Код:
```new a[] = {1,2,3,4,5,6,7,8,9};
and a[1] will give 2```
Oh yeah, mb; anyways. Is it possible to do it with a normal array?
Yes

new a[] = {1,2,3,4,5,6};

and to get a value a[0]

If you want to name each element of the array

You can do this

#define CLASS 1
#define ADMIN 2
#define IDIOT 3
#define JOKER 4
#define MAD 5

and a[MAD] = 1;
Yeah i knew that already. But i want to assign a number to a variable inside the array.
Updated my previous post which does it using defines.
I would swear there was a different way to do this by not using defines, can't remember that way though. I guess i will use this for now, and maybe a next poster will know the right way
pawn Код:
`enum eData {    eVar1,    eVar2}new gArray[][eData] {    {0, 2},    {7, 9}};`
OMG lol - I use it everywhere(almost) and I never thought of it

EDIT:Example how to use Neros code
enum PlayerInfo_t
{
Admin,
EpicPlayer
}
new PlayerInfo[MAX_PLAYERS][PlayerInfo_t];

and to use it PlayerInfo[playerid][Admin] = 1;
pawn Код:
`enum adminLevelData{    cpv,    createtele,    deletetele,    skin,    pgoto,    bring}new AdminLevel[adminLevelData][] ={    { cpv,          5 },    { createtele,   0 },    { deletetele,   0 },    { skin,         0 },    { pgoto,        0 },    { bring,        0 }};printf( "%i", AdminLevel[cpv][1] );`
Using it like that
Thanks both!
Why do you store for example into
pawn Код:
`AdminLevel[cpv][0] = cpv // Equals zero in this case`
?

Forum Jump:

Users browsing this thread: 1 Guest(s)