Data structures in Pawn
#6

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

pawn Code:
Vehicle[id][vModel] = 450;
Vehicle[id][vLock] = 1;
When using regular arrays, you can't be so sure, because the arrays can have different lengths

pawn Code:
new VehicleModel[200];
new VehicleLock[50];
pawn Code:
id = 150;
VehicleModel[id] = 450;
VehicleLock[id] = 1;
2) You can do this

pawn Code:
Vehicle[oneid] = Vehicle[otherid];
to copy the contents of one vehicle to another.

Cons:

1) You can't use sizeof on array elements

Example:

pawn Code:
format(Vehicle[vehicleid][vNumberPlate], sizeof(Vehicle[][vNumberPlate]), "sometext");
But you can define the size as a constant and use it

pawn Code:
#define MAX_NUMBER_PLATE 16
pawn Code:
vNumberPlate[MAX_NUMBER_PLATE],
pawn Code:
format(Vehicle[vehicleid][vNumberPlate], MAX_NUMBER_PLATE, "sometext");
2) You can't use more than 1 dimension on array elements

Doing

pawn Code:
vTrunk[5][2],
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.
Reply


Messages In This Thread
Data structures in Pawn - by MadeMan - 19.10.2012, 18:14
Re: Data structures in Pawn - by MadeMan - 19.10.2012, 18:36
Re: Data structures in Pawn - by lorizz - 19.10.2012, 21:15
Re: Data structures in Pawn - by Steven82 - 20.10.2012, 07:34
Re: Data structures in Pawn - by playbox12 - 20.10.2012, 10:09
Re: Data structures in Pawn - by MadeMan - 20.10.2012, 10:20
Re: Data structures in Pawn - by SuperViper - 20.10.2012, 15:00
Re: Data structures in Pawn - by MadeMan - 03.11.2012, 17:39
Re: Data structures in Pawn - by Finn - 03.11.2012, 17:54
Re: Data structures in Pawn - by MadeMan - 03.11.2012, 18:39
Re: Data structures in Pawn - by Michael@Belgium - 03.11.2012, 19:04
Re: Data structures in Pawn - by Finn - 03.11.2012, 19:32
Re: Data structures in Pawn - by Niko_boy - 04.11.2012, 05:01
Re: Data structures in Pawn - by [ABK]Antonio - 04.11.2012, 05:32
Re: Data structures in Pawn - by MadeMan - 04.11.2012, 08:41
Re: Data structures in Pawn - by Y_Less - 04.11.2012, 09:02
Re: Data structures in Pawn - by MadeMan - 04.11.2012, 11:24

Forum Jump:


Users browsing this thread: 2 Guest(s)