2d array -
Wesley221 - 07.05.2013
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
Re: 2d array -
Yashas - 07.05.2013
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
Re: 2d array -
Wesley221 - 07.05.2013
Oh yeah, mb; anyways. Is it possible to do it with a normal array?
Re: 2d array -
Yashas - 07.05.2013
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;
Re: 2d array -
Wesley221 - 07.05.2013
Yeah i knew that already. But i want to assign a number to a variable inside the array.
Re: 2d array -
Yashas - 07.05.2013
Updated my previous post which does it using defines.
Re: 2d array -
Wesley221 - 07.05.2013
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
AW: 2d array -
Nero_3D - 07.05.2013
pawn Код:
enum eData {
eVar1,
eVar2
}
new gArray[][eData] {
{0, 2},
{7, 9}
};
Re: 2d array -
Yashas - 07.05.2013
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;
Re: 2d array -
Wesley221 - 07.05.2013
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!
AW: 2d array -
BigETI - 07.05.2013
Why do you store for example into
pawn Код:
AdminLevel[cpv][0] = cpv // Equals zero in this case
?