String Formatting.
#1

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
    }
}
Reply
#2

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.
Reply
#3

Also you shouldn't edit assembly code (#emit) if you have no clue what you are doing
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)