Amount of items in an array. -
Jimmy0wns - 18.06.2015
So, this is something I've been stuck with for quite some time.
Lets say I have 5 items of vehicle information in my array. For example:
PHP код:
{451, 3.0, 4.0, 6.0, 220.0, 10000, 40000},
{591, 3.0, 4.0, 6.0, 220.0, 40000, 10000},
{512, 3.0, 4.0, 6.0, 220.0, 30000, 60000},
{485, 3.0, 4.0, 6.0, 220.0, 60000, 30000},
{412, 3.0, 4.0, 6.0, 220.0, 90000, 90000}
How would one get the amount of items in that array? I tried using
sizeof(thisarray[]); but without success, it gave me a random number.
Re: Amount of items in an array. -
Darrenr - 18.06.2015
Could this be done with foreach somehow? I've not used foreach much but im trying to figure it out using the standalone include - But i don't know how to use it that well
Re: Amount of items in an array. -
Jimmy0wns - 18.06.2015
Quote:
Originally Posted by Darrenr
Could this be done with foreach somehow? I've not used foreach much but im trying to figure it out using the standalone include - But i don't know how to use it that well
|
I've tried that, but it'll just result in a number which has been set as the max amount.
e.g: MAX_PLAYER_VEHICLES is set to 2000 and if you make a loop through that and save the result, it'll say 2000.
Re: Amount of items in an array. -
RajatPawar - 18.06.2015
pawn Код:
new arr[][] =
{
{1, 2, 3, 4},
{3, 4, 6, 6}
};
printf("%d %d", sizeof(arr), sizeof(arr[]));
Gave me results as 2 & 4.
Why didn't it work with yours?
Re: Amount of items in an array. -
Jimmy0wns - 18.06.2015
Quote:
Originally Posted by RajatPawar
pawn Код:
new arr[][] = { {1, 2, 3, 4}, {3, 4, 6, 6} }; printf("%d %d", sizeof(arr), sizeof(arr[]));
Gave me results as 2 & 4.
Why didn't it work with yours?
|
Probably because I do this all in a very different way, I use enums as well but I just couldn't think of the right terms when posting this topic.
I usually make an enum like this:
PHP код:
enum _VehicleData
{
vID,
vOwner[128],
vLocation[128],
vModel,
Float:vPosX,
Float:vPosY,
Float:vPosZ,
Float:vPosAngle,
vColor1,
vColor2,
vPrice,
vDefaultPrice,
vForSale,
Text3D:vText,
curVehID,
};
And then use this:
PHP код:
new VehicleData[MAX_VEHICLES][_VehicleData];
Whereas the items for this array get loaded with a MySQL query when the server starts.
Re: Amount of items in an array. -
Jimmy0wns - 18.06.2015
Solved it by using this.
PHP код:
new total;
for(new i; i<sizeof(VehicleData); i++)
{
if(VehicleData[i][vModel] == 0)
{
total = i;
break;
}
}
printf("%d", total);