SA-MP Forums Archive
Question about arrays? - 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: Question about arrays? (/showthread.php?tid=541426)



Question about arrays? - AndySedeyn - 11.10.2014

Hello guys

I've been developing a gang system whereas the first version works perfectly with some minor bugs.
I decided to rewrite it efficiently and this came up my mind, will this work correctly?

pawn Code:
enum gInfo
{
    Float:g_VehiclePos[MAX_GANG_VEHICLES][4],
}
new GangInfo[MAX_GANGS][gInfo];



Re: Question about arrays? - kristo - 11.10.2014

No, sadly pawn only supports 3-dimensional arrays. You would have to do it like this:

pawn Code:
enum gInfo
{
    Float:g_VehiclePosX[MAX_GANG_VEHICLES],
    Float:g_VehiclePosY[MAX_GANG_VEHICLES],
    Float:g_VehiclePosZ[MAX_GANG_VEHICLES],
    Float:g_VehiclePosA[MAX_GANG_VEHICLES],
}
new GangInfo[MAX_GANGS][gInfo];
Everything else is fine in this code.


Re: Question about arrays? - AndySedeyn - 11.10.2014

Quote:
Originally Posted by kvann
View Post
No, sadly pawn only supports 3-dimensional arrays. You would have to do it like this:

pawn Code:
enum gInfo
{
    Float:g_VehiclePosX[MAX_GANG_VEHICLES],
    Float:g_VehiclePosY[MAX_GANG_VEHICLES],
    Float:g_VehiclePosZ[MAX_GANG_VEHICLES],
    Float:g_VehiclePosA[MAX_GANG_VEHICLES],
}
new GangInfo[MAX_GANGS][gInfo];
Everything else is fine in this code.
Thanks for the answer man.


Re: Question about arrays? - Pottus - 11.10.2014

Quote:
Originally Posted by kvann
View Post
No, sadly pawn only supports 3-dimensional arrays. You would have to do it like this:

pawn Code:
enum gInfo
{
    Float:g_VehiclePosX[MAX_GANG_VEHICLES],
    Float:g_VehiclePosY[MAX_GANG_VEHICLES],
    Float:g_VehiclePosZ[MAX_GANG_VEHICLES],
    Float:g_VehiclePosA[MAX_GANG_VEHICLES],
}
new GangInfo[MAX_GANGS][gInfo];
Everything else is fine in this code.
Well actually that isn't entirely true sorta.

http://slice-vps.nl:7070/
pawn Code:
#include <a_samp>
#include <ppg>

enum etest
{
    test1[3],
    test2[3],
    test3[3],
}

new test[3][3][etest];

main() {

    test[0][0][test1][0] = 1;
    test[0][0][test1][1] = 2;
    test[0][0][test1][2] = 3;

    printf("%i,%i,%i", test[0][0][test1][0], test[0][0][test1][1], test[0][0][test1][2]);
   
}



Re: Question about arrays? - AndySedeyn - 11.10.2014

Can someone provide me documentation on what the array possibilities are within pawn?


Re: Question about arrays? - ThePhenix - 11.10.2014

As Pottus said, you could do it like this:
PHP Code:
enum gInfo
{
    
Float:g_VehiclePos[4],
}
new 
GangInfo[MAX_GANGS][MAX_GANG_VEHICLES][gInfo]; 
An example of the usage:

PHP Code:
    GangInfo[0][0][g_VehiclePos][0] = 343.1;
    
GangInfo[0][0][g_VehiclePos][1] = 563.1;
    
GangInfo[0][0][g_VehiclePos][2] = 73.1;
    
GangInfo[0][0][g_VehiclePos][3] = 3.1



Re: Question about arrays? - AndySedeyn - 11.10.2014

Interesting.

So I could do something like this as well?
pawn Code:
enum gInfo
{
    Float:g_VehiclePos[4];
}
new GangInfo[MAX_GANGS][gInfo],
    GangVehInfo[MAX_GANGS][MAX_GANG_VEHICLES][gInfo];
   
    GangVehInfo[0][0][g_VehiclePos][0] = 0.0;
    GangVehInfo[0][0][g_VehiclePos][1] = 0.0;
    GangVehInfo[0][0][g_VehiclePos][2] = 0.0;
    GangVehInfo[0][0][g_VehiclePos][3] = 0.0;
Edit: I used this method and it didn't give any compile error as it did with my starting code. Thanks for the information, I did learn something new today.


Re: Question about arrays? - Pottus - 12.10.2014

Instead of doing that I would just do this.

pawn Code:
enum gInfo
{
    Float:g_VehiclePosX,
    Float:g_VehiclePosY,
    Float:g_VehiclePosZ,
}
It's probably rare that would will actually need use my example.

In fact I have only ever had to do this once with our older map editor and vehicles and you can see I still had to store the text outside of the enum due to limitations.

pawn Code:
enum vehicle_info {
    object_id,
    vehicle_id,
    medit_modelid,
    Float:ox,
    Float:oy,
    Float:oz,
    Float:rx,
    Float:ry,
    Float:rz,
    Material_Index[MAX_MATERIAL_INDEX],
    Material_Color[MAX_MATERIAL_INDEX],
    usetext,
    Material_FontFace,
    Material_FontSize,
    Material_FontBold,
    Material_FontColor,
    Material_BackColor,
    Material_Alignment,
    Material_TextFontSize
}

// Needs to be created outside of the ENUM due to limitations
new Material_Veh_Text[MAX_PLAYERS][MAX_VEH_OBJECTS][64];

// Vehicle object list for each player
new vehicles[MAX_PLAYERS][MAX_VEH_OBJECTS][vehicle_info];