Question about arrays?
#1

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];
Reply
#2

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

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

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]);
   
}
Reply
#5

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

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

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

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];
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)