Is it possible to make an Array inside an Array? -
Warfish - 11.02.2012
I am making a racing script that saves all the race and chechpoint data in a MySQL database.
So here is my problem:
I have one array and it has to be linked to the other, my checkpoint data has to be linked to the race Id.
Код:
#define MAX_RACES 5
#define MAX_CHECKPOINTS 40
enum eCheckpoint {
cId,
Float:cX,
Float:cY,
Float:cZ
}
enum eRace {
rId,
rName[50],
rCreator[50],
Float:rAngle,
rVehicle,
rCheckpoints[MAX_CHECKPOINTS][eCheckpoint]
}
new gRace[MAX_RACES][eRace];
Error message:
Код:
\SA-MP server\gamemodes\race.pwn(62) : error 001: expected token: "}", but found "["
Re: Is it possible to make an Array inside an Array? -
Twisted_Insane - 11.02.2012
You mean this one?
pawn Код:
new gRace[MAX_RACES][eRace];
Of course it should be possible, I got some, too. Example from one of mine:
pawn Код:
if(PlayerInfo[playerid][pAdmin] > 1)
"PlayerInfo" is holding the arrays from the playerid and the adminlevel, which is in my enum!
Hope I could help usefully!
Re: Is it possible to make an Array inside an Array? -
Warfish - 11.02.2012
I can also make it with just 2 arrays but I really want to make this way working..
@Twisted_Insane: thats just a normal array, I use them frequently
Re: Is it possible to make an Array inside an Array? -
Twisted_Insane - 11.02.2012
Well, why don't you just try it then and post us your result here? I say it IS possible, maybe it isn't and I am wrong! So if I were you, I'd test it by myself now!
Take a look here, too:
https://sampforum.blast.hk/showthread.php?tid=159430
Re: Is it possible to make an Array inside an Array? -
Warfish - 11.02.2012
Yes I get that but my array is 1 dimension deeper..
AW: Is it possible to make an Array inside an Array? -
Nero_3D - 11.02.2012
An enum is just a list of constant variables and therefore you cant use more than one dimension inside an enum
Re: Is it possible to make an Array inside an Array? -
Warfish - 11.02.2012
oh .. thanks man, so I have to make 2 arrays..
Or is there an otherway?
AW: Is it possible to make an Array inside an Array? -
Nero_3D - 11.02.2012
I would use two arrays because you wouldnt create wasted memeory
Because now you create 40 cells (checkpoints) for each race
But I dont think that each race uses all 40 cells
You could compress your 2d array in 1d with some limitations
Only one type of variable but that doesnt matter if you know that pawn always uses 32 bit variables
Also I removed cId and rId because I cant see why you need them
pawn Код:
#define MAX_RACES 5
#define MAX_CHECKPOINTS 40
enum eCheckpoint {
cX,
cY,
cZ
}
enum eRace {
rName[50],
rCreator[50],
Float: rAngle,
rVehicle,
Float: rCheckpoints[eCheckpoint: MAX_CHECKPOINTS * eCheckpoint]
}
new gRace[MAX_RACES][eRace];
#define gRace[%0][rCheckpoints][%1][%2] gRace[%0][rCheckpoints][(eCheckpoint: (%1) * eCheckpoint) + (%2)]
Re: Is it possible to make an Array inside an Array? -
Warfish - 11.02.2012
Thanks a lot but I just fixed it on my own way, its interesting how you solved it.
Here is my way:
Код:
#define MAX_RACES 5
#define MAX_CHECKPOINTS 40
enum eCheckpoint {
cId,
Float:cX,
Float:cY,
Float:cZ
}
new gCheckpoint[MAX_RACES][MAX_CHECKPOINTS][eCheckpoint]
enum eRace {
rId,
rName[50],
rCreator[50],
Float:rAngle,
rVehicle
}
new gRace[MAX_RACES][eRace];