Can I make array of functions?
#1

I know this use is ok:
Код:
new array[2] = { 1, 2 };
But is any way to make something like this:
Код:
new cars[2] = { CreateVehicle(0, 0, 0, 0, 0, -1, -1, 200), CreateVehicle(0, 0, 0, 0, 0, -1, -1, 200) };
Reply
#2

No, but you can make a function that accepts a parameter to do what you want.
pawn Код:
CreateSpecialVehicle(Something)
{
    switch (Something)
    {
        case 1: return CreateVehicle(562, 0, 0, 0, 0, -1, -1, 200);
        case 2: return CreateVehicle(412, 0, 0, 0, 0, -1, -1, 200);
        case 3: return CreateVehicle(592, 0, 0, 0, 0, -1, -1, 200);
        case 4: return CreateVehicle(517, 0, 0, 0, 0, -1, -1, 200);
    }

    return 0;
}
What you want, is a way to store function-pointers along with it's parameters.
AFAIK, pawn doesn't handle function pointers.
Reply
#3

Really I need for loop
Код:
for(i=0; i<=sizeof(cars); i++)
Just I don't want to create
Код:
cars[0] = ...
cars[1] = ...
cars[2] = ...
cars[3] = ...
...
It's easier:
Код:
cars[size] = { car, car, car ... }
Reply
#4

You have an array of model-id's and coordinates, and you want to create those vehicles with a loop?
Reply
#5

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
You have an array of model-id's and coordinates, and you want to create those vehicles with a loop?
Something that.
Reply
#6

Something like this?
pawn Код:
enum TDefinedCars
{
    Model,
    Float:SpawnX,
    Float:SpawnY,
    Float:SpawnZ
}

new DefinedCars[20][TDefinedCars] =
{
    {562, 100.0, 100.0, 5.0},
    {418, 150.0, 258.1, 7.8},
    ...
    {519, -130.5, 179.8, 11.4}
}


new Cars[20];

for (new i; i < 20: i++)
    Cars[i] = CreateVehicle(DefinedCars[i][Model], DefinedCars[i][SpawnX], DefinedCars[i][SpawnY], DefinedCars[i][SpawnZ], 0.0, 0, 0, 60);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)