noob question about sizeof() - 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: noob question about sizeof() (
/showthread.php?tid=538050)
noob question about sizeof() -
dudaefj - 19.09.2014
hello
I know it is wrong, but how I do it right?
PHP код:
sizeof(VehicleInfo[vehicleid][vPlaca])
PHP код:
forward SetVehicleNumberPlateEx(vehicleid, numberplate[]);
public SetVehicleNumberPlateEx(vehicleid, numberplate[])
{
format(VehicleInfo[vehicleid][vPlaca], sizeof(VehicleInfo[vehicleid][vPlaca]), "%s", numberplate);
SetVehicleNumberPlate(vehicleid, VehicleInfo[vehicleid][vPlaca]);
}
Re: noob question about sizeof() -
Dignity - 19.09.2014
This is the correct way of doing it.
Re: noob question about sizeof() -
Vince - 19.09.2014
Can't be reliably retrieved. Put the number itself or a definition instead.
Re: noob question about sizeof() -
Stinged - 19.09.2014
Just enter its size.
Also, you should use strcpy for this, not format.
pawn Код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)
strcpy(VehicleInfo[vehicleid][vPlaca], numberplate, SIZE HERE);
Re: noob question about sizeof() -
dudaefj - 19.09.2014
Quote:
Originally Posted by Mionee
This is the correct way of doing it.
|
no, it's not.
the following error is returned:
Quote:
BSL2.pwn(2603) : error 001: expected token: "]", but found "-identifier-"
BSL2.pwn(2603) : warning 215: expression has no effect
BSL2.pwn(2603) : error 001: expected token: ";", but found "]"
BSL2.pwn(2603) : error 029: invalid expression, assumed zero
BSL2.pwn(2603) : fatal error 107: too many error messages on one line
|
Quote:
Originally Posted by Vince
Can't be reliably retrieved. Put the number itself or a definition instead.
|
are you sure?
It's so sad ;(
Re: noob question about sizeof() -
Vince - 19.09.2014
Quote:
Originally Posted by dudaefj
are you sure?
It's so sad ;(
|
Yes. For a regular array, the correct way of doing it would be:
pawn Код:
sizeof(array[])
// or
sizeof(array[][])
But since this concerns an enum, I have no idea what size would be returned. I suppose it'd be the largest one. So if you have something like:
pawn Код:
enum myVars {
string1[64],
plate[16]
}
There'd be a good chance that it'd return 64, which is not what you want.