SA-MP Forums Archive
Can I make array of functions? - 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)
+--- Thread: Can I make array of functions? (/showthread.php?tid=494075)



Can I make array of functions? - Stuneris - 11.02.2014

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) };



Re: Can I make array of functions? - PowerPC603 - 11.02.2014

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.


Re: Can I make array of functions? - Stuneris - 11.02.2014

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



Re: Can I make array of functions? - PowerPC603 - 11.02.2014

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


Re: Can I make array of functions? - Stuneris - 11.02.2014

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.


Re: Can I make array of functions? - PowerPC603 - 11.02.2014

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);