String Formatting. - 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: String Formatting. (
/showthread.php?tid=552617)
String Formatting. -
zT KiNgKoNg - 25.12.2014
I'm having an issue with a custom string formatting 'Stock', thats throwing out "error 047: array sizes do not match, or destination array is too small", Even though i'm using this kinda of system in a few more functions.
pawn Code:
stock CreateFormattedString(const msg[], {Float,_}:...)
{
static
string[268];
if (numargs() == 1)
{
return msg;
}
else
{
new args = numargs();
while (--args >= 1)
{
#emit LCTRL 5
#emit LOAD.S.alt args
#emit SHL.C.alt 2
#emit ADD
#emit ADD.C 12
#emit LOAD.I
#emit PUSH.pri
}
#emit PUSH.S msg
#emit PUSH.C 268
#emit PUSH.C string
#emit LOAD.S.pri 8
#emit PUSH.pri
#emit SYSREQ.C format
return string;
#emit LCTRL 5
#emit SCTRL 4
#emit RETN
}
}
Re: String Formatting. -
Misiur - 25.12.2014
This comment (especially the pdf excerpt) will explain as to why this error pops up. You can solve it like:
pawn Code:
if (numargs() == 1)
{
strcat((string[0] = EOS, string), msg);
return string;
}
(This is macroless strcpy)
There is other way using macros, but detecting single parameter is way more difficult than detecting none or more than 1.
AW: String Formatting. -
Nero_3D - 25.12.2014
Also you shouldn't edit assembly code (#emit) if you have no clue what you are doing