sscanf warning.
#1

Well, I've been following a tutorial on how to use ZCMD and sscanf and in the tutorial, they made a /me command but when I followed it I noticed a few unnecessary parts so I removed them.

When I used the command everything worked just fine and I was like "lol, what did he add those lines"
When I exited the server, I noticed a warning in the console saying: "sscanf warning: Strings without a length are depracated, please add a destination size".

Then I coppied the tutorial's /me command and the command worked just fine, but again.. I noticed the console with warnings, this time several warnings, so I just removed their parts and made the command by my way.

Anyway.. I still got that warning and I can not find a way to solve it; here's the code:
pawn Код:
CMD:me(playerid, params[])
{
    GetPlayerName(playerid,pname,sizeof(pname));
    if(sscanf(params, "s", str)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: /me [text]");
    format(s, sizeof(s), "* %s %s", pname, str);
    SendClientMessageToAll(COLOR_RED, s);
    return 1;
}

If I done anything wrong please tell me. I am just starting to learn how to use ZCMD and sscanf and converting all my script into it so any tip will be appreciated!
Reply
#2

pawn Код:
CMD:me(playerid, params[])
{
    GetPlayerName(playerid,pname,sizeof(pname));
    if(sscanf(params, "s[24]", str)) return SendClientMessage(playerid, COLOR_USAGE, "USAGE: /me [text]");
    format(s, sizeof(s), "* %s %s", pname, str);
    SendClientMessageToAll(COLOR_RED, s);
    return 1;
}
It's because you're not adding the size of the string when using the sscanf command. Since we cannot use 'MAX_PLAYER_NAME' in it, we must use 24 because that is what 'MAX_PLAYER_NAME' is defined as.

This only happens if you're using sscanf2, the plugin version.

Here is an example:

pawn Код:
COMMAND:something(playerid, params[])
{
    new text[128];
    if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, COLOUR_WHITE, "/something [TEXT]");
    else
    {
        print(text);
    }
    return 1;
}
We've given the text variable a size of 128, therefore we must also say we're using 128 when using sscanf.

pawn Код:
if(sscanf(params, "s[256]", text)) return SendClientMessage(playerid, COLOUR_WHITE, "/something [TEXT]"); //WRONG
if(sscanf(params, "s", text)) return SendClientMessage(playerid, COLOUR_WHITE, "/something [TEXT]"); //WRONG
if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, COLOUR_WHITE, "/something [TEXT]"); //RIGHT
Reply
#3

Ah, I see... thank you. But, the str length is 128 doesn't it mean I don't have to define the s as an array aswell?
Anyway, I got it. I need to define it as the needed length. Thank you!

EDIT: I got it, thank you so much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)