Different size of 2D array in a 3D array?
#1

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

Here's an easy way:

pawn Код:
new Float:RaceCheckpoints[number_of_checkpoints][4] =
{
    {x, y, z, size},
    {x, y, z, size}
};
Reply
#3

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

I tried the same and had the same issue. I never managed to get all races in one array done.
Reply
#5

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


Forum Jump:


Users browsing this thread: 1 Guest(s)