20.10.2012, 10:20
I changed the question, maybe it's better now.
I used regular arrays before (the first option), but now I prefer enums (the second option).
Pros and cons of enums:
Pros:
1) You know where the variable belongs
If you use an id on vModel, you can be sure that you can use the same id on vLock too
When using regular arrays, you can't be so sure, because the arrays can have different lengths
2) You can do this
to copy the contents of one vehicle to another.
Cons:
1) You can't use sizeof on array elements
Example:
But you can define the size as a constant and use it
2) You can't use more than 1 dimension on array elements
Doing
in enum declaration is not valid.
Can't think of anything else at the moment.
I'm hoping to put together a full list of pros and cons of using an enum as a data structure. So if you can add something, would be great.
I used regular arrays before (the first option), but now I prefer enums (the second option).
Pros and cons of enums:
Pros:
1) You know where the variable belongs
If you use an id on vModel, you can be sure that you can use the same id on vLock too
pawn Code:
Vehicle[id][vModel] = 450;
Vehicle[id][vLock] = 1;
pawn Code:
new VehicleModel[200];
new VehicleLock[50];
pawn Code:
id = 150;
VehicleModel[id] = 450;
VehicleLock[id] = 1;
pawn Code:
Vehicle[oneid] = Vehicle[otherid];
Cons:
1) You can't use sizeof on array elements
Example:
pawn Code:
format(Vehicle[vehicleid][vNumberPlate], sizeof(Vehicle[][vNumberPlate]), "sometext");
pawn Code:
#define MAX_NUMBER_PLATE 16
pawn Code:
vNumberPlate[MAX_NUMBER_PLATE],
pawn Code:
format(Vehicle[vehicleid][vNumberPlate], MAX_NUMBER_PLATE, "sometext");
Doing
pawn Code:
vTrunk[5][2],
Can't think of anything else at the moment.
I'm hoping to put together a full list of pros and cons of using an enum as a data structure. So if you can add something, would be great.