Problem with optional parameters sscanf
#1

Hi everyone !

I use the sscanf for create a phone system, I have a problem with two optional parameters.
For example, I send "/t appel 223" in game, it return this warning:

Quote:

[17:09:53] sscanf warning: Unknown format specifier '[', skipping.
[17:09:53] sscanf warning: Unknown format specifier '3', skipping.
[17:09:53] sscanf warning: Unknown format specifier '2', skipping.
[17:09:53] sscanf warning: Unknown format specifier ']', skipping.
[17:09:53] sscanf warning: Format specifier does not match parameter count.

The command:

pawn Код:
CMD:t(playerid, params[])
{
    new option[16], numero, texte[64], Float:x, Float:y, Float:z, telPID;
    if(playerInfo[playerid][telephone] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Vous n'avez pas de telephone portable");
    if(freezes[playerid] == true || mute[playerid] == true) return SCM(playerid, TEL, "ARP "BLANC1"Vous ne pouvez pas utilisez votre telephone pour le moment");
    if(sscanf(params, "s[16]I()S()[32]", option, numero, texte)) { return SCM(playerid, TEL, "ARP: "BLANC1"/t <nom>"), SCM(playerid, TEL, "ARP: "BLANC1"Nom: "BLANC1"allumer, eteindre, appel, sms, rac(rocher), dec(rocher)"); }
    if(!strcmp(option, "allumer", true))
    {
        if(playerInfo[playerid][telephoneStatus] == 1) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est dйjа allumй.");
        playerInfo[playerid][telephoneStatus]=1;
        SCM(playerid, TEL, "ARP: "BLANC1"Vous avez allumй votre telephone portable.");
        GetPlayerPos(playerid, x, y, z);
        PlayAudioStreamForPlayer(playerid, TELON, x, y, z, 5.0, 1);
    }
    else if(!strcmp(option, "eteindre", true))
    {
        if(playerInfo[playerid][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est dйjа йteint.");
        playerInfo[playerid][telephoneStatus]=0;
        SCM(playerid, TEL, "ARP: "BLANC1"Vous avez йteint votre telephone portable.");
        GetPlayerPos(playerid, x, y, z);
        PlayAudioStreamForPlayer(playerid, TELON, x, y, z, 5.0, 1);
    }
    else if(!strcmp(option, "appel", true))
    {
        if(numero == 0) return SCM(playerid, TEL, "ARP: "BLANC1"/t appel <numero>");
        if(playerInfo[playerid][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est йteint.");
        else if(playerInfo[playerid][telephoneCredits] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Vous n'avez plus de crйdits.");
        else if(numero == playerInfo[playerid][telephone]) return SCM(playerid, TEL, "ARP: "BLANC1"Vous ne pouvez pas vous appelez.");
        telPID = ReturnIdByNum(numero);
        if(telPID == -1) return SCM(playerid, TEL, "ARP: "BLANC1"Numйro incorrect.");
        if(playerInfo[telPID][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Le portable du correspondant est йteint.");
        else if(inTel[telPID] >= 0) return SCM(playerid, TEL, "ARP: "BLANC1"Le correspondant est actuellement en ligne, rйessayer plus tard...");
        else if(inTel[playerid] >= 0) return SCM(playerid, TEL, "ARP: "BLANC1"Vous кtes dйjа en communication.");
        inTel[telPID]=playerid, inTel[playerid]=telPID, telAuthor[playerid]=1;
        PlayAudioStreamForPlayer(playerid, SONNERIE, x, y, z, 5.0, 1);
        PlayAudioStreamForPlayer(playerid, SONNERIE2, x, y, z, 5.0, 1);
        format(commandes, sizeof(commandes), "ARP: "BLANC1"Composition du numero \"%d\", appel en cours...", numero);
        SCM(playerid, TEL, commandes);
        format(commandes, sizeof(commandes), "ARP: "BLANC1"(Sonnerie d'appel) %d", playerInfo[playerid][telephone]);
        SCM(telPID, TEL, commandes);
        telTimer[telPID]=SetTimerEx("EndCall", 30000, false, "iii", playerid, telPID, 3);
    }
    else if(!strcmp(option, "dec", true) || !strcmp(option, "decrocher", true))
    {
        if(playerInfo[playerid][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est йteint.");
        if(inTel[playerid] == -1) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone ne sonne pas.");
        SCM(playerid, TEL, "ARP: "BLANC1"Vous avez dйcrochй.");
        EndCall(playerid, inTel[playerid], ACCEPT);
    }
    else if(!strcmp(option, "rac", true) || !strcmp(option, "raccrocher", true))
    {
        if(playerInfo[playerid][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est йteint.");
        if(inTel[playerid] == -1) return SCM(playerid, TEL, "ARP: "BLANC1"Vous n'кtes pas en communication.");
        SCM(playerid, TEL, "ARP: "BLANC1"Vous avez racrochй.");
        EndCall(playerid, inTel[playerid], REJECT);
    }
    else if(!strcmp(option, "sms", true))
    {
        if(numero == 0) return SCM(playerid, TEL, "ARP: "BLANC1"/t sms <numero> <texte>");
        else if(strlen(texte) == 0) return SCM(playerid, TEL, "ARP: "BLANC1"/t sms <numero> <texte>");
        if(playerInfo[playerid][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est йteint.");
        else if(inTel[playerid] != -1) return SCM(playerid, TEL, "ARP: "BLANC1"Vous кtes en communication.");
        else if(playerInfo[playerid][telephoneCredits] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Vous n'avez plus de crйdits.");
        else if(numero == playerInfo[playerid][telephone]) return SCM(playerid, TEL, "ARP: "BLANC1"Vous ne pouvez pas vous envoyez un sms.");
        telPID = ReturnIdByNum(numero);
        if(telPID == -1) return SCM(playerid, TEL, "ARP: "BLANC1"Numйro incorrect.");
        if(playerInfo[telPID][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Le portable du correspondant est йteint.");
        PlayAudioStreamForPlayer(telPID, TELON, x, y, z, 5.0, 1);
        format(commandes, sizeof(commandes), "Message envoyй а %d: "BLANC1"\"%s\"", numero, texte);
        SCM(playerid, TEL, commandes);
        format(commandes, sizeof(commandes), "Message envoyй de %d: "BLANC1"\"%s\"", playerInfo[playerid][telephone], texte);
        SCM(telPID, TEL, commandes);
        playerInfo[playerid][telephoneCredits]--;
    }
    return 1;
}
Reply
#2

You don't have the default value/text and the length should be before the text. An example:
pawn Код:
"s[16]I(0)S[32](Some Text)"
Reply
#3

Thank you for your help but the problem still persists, here are the errors that it returns when I send "/t appel 223":

Quote:

[17:23:04] sscanf warning: No default value found.
[17:23:04] sscanf warning: Unknown format specifier '[', skipping.
[17:23:04] sscanf warning: Unknown format specifier '3', skipping.
[17:23:04] sscanf warning: Unknown format specifier '2', skipping.
[17:23:04] sscanf warning: Unknown format specifier ']', skipping.
[17:23:04] sscanf warning: Unknown format specifier '(', skipping.
[17:23:04] sscanf error: No specified parameters found.

New command:

pawn Код:
CMD:t(playerid, params[])
{
    new option[16], numero, texte[64], Float:x, Float:y, Float:z, telPID;
    if(playerInfo[playerid][telephone] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Vous n'avez pas de telephone portable");
    if(freezes[playerid] == true || mute[playerid] == true) return SCM(playerid, TEL, "ARP "BLANC1"Vous ne pouvez pas utilisez votre telephone pour le moment");
    if(sscanf(params, "s[16]I(0)S[32](Aucun)", option, numero, texte)) { return SCM(playerid, TEL, "ARP: "BLANC1"/t <nom>"), SCM(playerid, TEL, "ARP: "BLANC1"Nom: "BLANC1"allumer, eteindre, appel, sms, rac(rocher), dec(rocher)"); }
    if(!strcmp(option, "allumer", true))
    {
        if(playerInfo[playerid][telephoneStatus] == 1) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est dйjа allumй.");
        playerInfo[playerid][telephoneStatus]=1;
        SCM(playerid, TEL, "ARP: "BLANC1"Vous avez allumй votre telephone portable.");
        GetPlayerPos(playerid, x, y, z);
        PlayAudioStreamForPlayer(playerid, TELON, x, y, z, 5.0, 1);
    }
    else if(!strcmp(option, "eteindre", true))
    {
        if(playerInfo[playerid][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est dйjа йteint.");
        playerInfo[playerid][telephoneStatus]=0;
        SCM(playerid, TEL, "ARP: "BLANC1"Vous avez йteint votre telephone portable.");
        GetPlayerPos(playerid, x, y, z);
        PlayAudioStreamForPlayer(playerid, TELON, x, y, z, 5.0, 1);
    }
    else if(!strcmp(option, "appel", true))
    {
        if(numero == 0) return SCM(playerid, TEL, "ARP: "BLANC1"/t appel <numero>");
        if(playerInfo[playerid][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est йteint.");
        else if(playerInfo[playerid][telephoneCredits] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Vous n'avez plus de crйdits.");
        else if(numero == playerInfo[playerid][telephone]) return SCM(playerid, TEL, "ARP: "BLANC1"Vous ne pouvez pas vous appelez.");
        telPID = ReturnIdByNum(numero);
        if(telPID == -1) return SCM(playerid, TEL, "ARP: "BLANC1"Numйro incorrect.");
        if(playerInfo[telPID][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Le portable du correspondant est йteint.");
        else if(inTel[telPID] >= 0) return SCM(playerid, TEL, "ARP: "BLANC1"Le correspondant est actuellement en ligne, rйessayer plus tard...");
        else if(inTel[playerid] >= 0) return SCM(playerid, TEL, "ARP: "BLANC1"Vous кtes dйjа en communication.");
        inTel[telPID]=playerid, inTel[playerid]=telPID, telAuthor[playerid]=1;
        PlayAudioStreamForPlayer(playerid, SONNERIE, x, y, z, 5.0, 1);
        PlayAudioStreamForPlayer(playerid, SONNERIE2, x, y, z, 5.0, 1);
        format(commandes, sizeof(commandes), "ARP: "BLANC1"Composition du numero \"%d\", appel en cours...", numero);
        SCM(playerid, TEL, commandes);
        format(commandes, sizeof(commandes), "ARP: "BLANC1"(Sonnerie d'appel) %d", playerInfo[playerid][telephone]);
        SCM(telPID, TEL, commandes);
        telTimer[telPID]=SetTimerEx("EndCall", 30000, false, "iii", playerid, telPID, 3);
    }
    else if(!strcmp(option, "dec", true) || !strcmp(option, "decrocher", true))
    {
        if(playerInfo[playerid][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est йteint.");
        if(inTel[playerid] == -1) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone ne sonne pas.");
        SCM(playerid, TEL, "ARP: "BLANC1"Vous avez dйcrochй.");
        EndCall(playerid, inTel[playerid], ACCEPT);
    }
    else if(!strcmp(option, "rac", true) || !strcmp(option, "raccrocher", true))
    {
        if(playerInfo[playerid][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est йteint.");
        if(inTel[playerid] == -1) return SCM(playerid, TEL, "ARP: "BLANC1"Vous n'кtes pas en communication.");
        SCM(playerid, TEL, "ARP: "BLANC1"Vous avez racrochй.");
        EndCall(playerid, inTel[playerid], REJECT);
    }
    else if(!strcmp(option, "sms", true))
    {
        if(numero == 0) return SCM(playerid, TEL, "ARP: "BLANC1"/t sms <numero> <texte>");
        else if(!strcmp(texte, "Aucun", true)) return SCM(playerid, TEL, "ARP: "BLANC1"/t sms <numero> <texte>");
        if(playerInfo[playerid][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Votre telephone est йteint.");
        else if(inTel[playerid] != -1) return SCM(playerid, TEL, "ARP: "BLANC1"Vous кtes en communication.");
        else if(playerInfo[playerid][telephoneCredits] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Vous n'avez plus de crйdits.");
        else if(numero == playerInfo[playerid][telephone]) return SCM(playerid, TEL, "ARP: "BLANC1"Vous ne pouvez pas vous envoyez un sms.");
        telPID = ReturnIdByNum(numero);
        if(telPID == -1) return SCM(playerid, TEL, "ARP: "BLANC1"Numйro incorrect.");
        if(playerInfo[telPID][telephoneStatus] == 0) return SCM(playerid, TEL, "ARP: "BLANC1"Le portable du correspondant est йteint.");
        PlayAudioStreamForPlayer(telPID, TELON, x, y, z, 5.0, 1);
        format(commandes, sizeof(commandes), "Message envoyй а %d: "BLANC1"\"%s\"", numero, texte);
        SCM(playerid, TEL, commandes);
        format(commandes, sizeof(commandes), "Message envoyй de %d: "BLANC1"\"%s\"", playerInfo[playerid][telephone], texte);
        SCM(telPID, TEL, commandes);
        playerInfo[playerid][telephoneCredits]--;
    }
    return 1;
}
Reply
#4

Try swapping the length and the text in "S" specifier:
pawn Код:
"s[16]I(0)S(Aucun)[32]"
Reply
#5

Thank you very much for your help, the problem is solved!
+ rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)