SSCANF error 035: argument type mismatch (argument 2)
#1

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

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

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

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

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 ?
Reply
#6

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

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)