Different size of 2D array in a 3D array? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Different size of 2D array in a 3D array? (
/showthread.php?tid=179726)
[Solved]Different size of 2D array in a 3D array? -
leong124 - 28.09.2010
Hello everyone,
I'm writing a race script and I'm finding a method to store all race coordinates within one variable.
The variable needs to contain the x,y,z coordinates and the size of all of the checkpoints of more than 1 races.
The problem is that the number of checkpoints of the races are not the same, and the compiler says that the 3D array need to be fully initialized.(Each 2D array nedd to be the same size?)
Is there any method to store such 2D arrays with different size in one 3D array?Thanks.
Re: Different size of 2D array in a 3D array? -
LarzI - 28.09.2010
Here's an easy way:
pawn Код:
new Float:RaceCheckpoints[number_of_checkpoints][4] =
{
{x, y, z, size},
{x, y, z, size}
};
Re: Different size of 2D array in a 3D array? -
leong124 - 28.09.2010
Yes I know this,but this is only for 1 race only.
I want to store such arrays(with different number of checkpoints) within 1 larger array.
For example:
Код:
new Float:RaceCheckpoints[number_of_races][number_of_checkpoints][4] =
{
{
{x, y, z, size},
{x, y, z, size}//2 checkpoints
},
{
{x, y, z, size},
{x, y, z, size},
{x, y, z, size},
{x, y, z, size}//4 checkpoints
}
};
Something like this so that I can access the data with:
Код:
SetPlayerCheckpoint(playerid,RaceCheckpoints[current_race[playerid]][current_checkpoint[playerid]][x],RaceCheckpoints[current_race[playerid]][current_checkpoint[playerid]][y],RaceCheckpoints[current_race[playerid]][current_checkpoint[playerid]][z],RaceCheckpoints[current_race[playerid]][current_checkpoint[playerid]][size]);
But the compiler says that the array need to be fully initialized.
Re: Different size of 2D array in a 3D array? -
woot - 28.09.2010
I tried the same and had the same issue. I never managed to get all races in one array done.
Re: Different size of 2D array in a 3D array? -
leong124 - 28.09.2010
ok,I'll try method 3 for user-friendly(still easy to add races) and still save some RAM.
method 2 is bad for a race with 20 checkpoints while another has 100.
Thanks all.