SA-MP Forums Archive
SSCANF error 035: argument type mismatch (argument 2) - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: SSCANF error 035: argument type mismatch (argument 2) (/showthread.php?tid=224039)



SSCANF error 035: argument type mismatch (argument 2) - DeltaAirlines12 - 10.02.2011

I've got:

pawn Код:
if (strcmp("/o", cmdtext, true) == 0)
    {
    new text,string[70], pName[MAX_PLAYER_NAME];
    if(sscanf("s",text)) return SendClientMessage(playerid,COLOR_ERROR,"Usage: /o [Msg]"); // line with error
    GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
    format(string,sizeof string,"(( %s: %s))",pName,text);
    SendClientMessageToAll(COLOR_GREY,string);
    return 1;
    }
but get:

Код:
error 035: argument type mismatch (argument 2)
it's done with SSCANF. Anyone know whats wrong? Thanks.


Re: SSCANF error 035: argument type mismatch (argument 2) - Hal - 10.02.2011

pawn Код:
if(sscanf(cmdtext,"s",text)) return SendClientMessage(playerid,COLOR_ERROR,"Usage: /o [Msg]");
sscanf(cmdtext

you were missing cmdtext, and that is where sscanf extracts the parameters from.


Re: SSCANF error 035: argument type mismatch (argument 2) - Antonio [G-RP] - 10.02.2011

I suggest, if you're using sscanf, switching to zcmd or dcmd. They are easier to work with, and faster.


Re: SSCANF error 035: argument type mismatch (argument 2) - Mean - 11.02.2011

Quote:
Originally Posted by Antonio [G-RP]
Посмотреть сообщение
I suggest, if you're using sscanf, switching to zcmd or dcmd. They are easier to work with, and faster.
+ 1, SSCANF doesn't make much use if you use STRCMP, you should either use ZCMD or YCMD.


Re: SSCANF error 035: argument type mismatch (argument 2) - dice7 - 11.02.2011

Quote:
Originally Posted by Mean
Посмотреть сообщение
+ 1, SSCANF doesn't make much use if you use STRCMP, you should either use ZCMD or YCMD.
And why not ?


Re: SSCANF error 035: argument type mismatch (argument 2) - PowerPC603 - 11.02.2011

Also an error:
pawn Код:
new text,string[70], pName[MAX_PLAYER_NAME];
    if(sscanf("s",text)) return SendClientMessage(playerid,COLOR_ERROR,"Usage: /o [Msg]"); // line with error
Should be:
pawn Код:
new text[128], string[70], pName[MAX_PLAYER_NAME];
    if(sscanf(cmdtext, "s[128]",text)) return SendClientMessage(playerid,COLOR_ERROR,"Usage: /o [Msg]"); // line with error
You were reading text into an integer variable, while you gave sscanf the instruction to extract a string.


Re: SSCANF error 035: argument type mismatch (argument 2) - Rachael - 11.02.2011

Quote:
Originally Posted by Mean
Посмотреть сообщение
+ 1, SSCANF doesn't make much use if you use STRCMP, you should either use ZCMD or YCMD.
actually this is true. sscanf does not really make much sense without zcmd, or ycmd. Its possible to get it to work, but its ugly
[edit]
Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
Also an error:
Should be:
pawn Код:
new text[128], string[70], pName[MAX_PLAYER_NAME];
    if(sscanf(cmdtext, "s[128]",text)) return SendClientMessage(playerid,COLOR_ERROR,"Usage: /o [Msg]"); // line with error
You are also wrong, why would you assume that the OP is using the plugin version of sscanf without mentioning this in your reply. Also, why would you suggest extracting a string length of 128 to be formatted into a string of size 70?

using sscanf to extract a single parameter kind of defeats the purpose.

finally, cmdtext will include the /o command ( in this example ) so this is what sscanf will extract, not the text following.

so all you really need is something like this...
pawn Код:
if(!strcmp(cmdtext,"/o",true,2))
{
     if(strlen(cmdtext) < 4) return SendClientMessage(playerid,COLOR_COLOR,"USAGE: /o [text]");
     strdel(cmdtext,0,3);
     new
          string[128],
          pName[MAX_PLAYER_NAME]
     ;
     GetPlayerName(playerid,pName,sizeof(pName));
     format(string,sizeof(string),"(( %s : %s ))",pName,cmdtext);
     SendClientMessageToAll(COLOR_COLOR,string);
     return 1;
}
having said this, it still isn't perfect because adding this to your script will preclude you from having any other commands starting with /o, so you would kind of have to use strtok.
This brings us back to the reason why using zcmd is so much easier
pawn Код:
CMD:o(playerid,params[])
{
     if(isnull(params)) return SendClientMessage(playerid,COLOR_COLOR,"USAGE: /o [text]");
     new
          string[128],
          pName[MAX_PLAYER_NAME]
     ;
     GetPlayerName(playerid,pName,sizeof(pName));
     format(string,sizeof(string),"(( %s : %s ))",pName,params);
     SendClientMessageToAll(COLOR_COLOR,string);
     return 1;
}