SA-MP Forums Archive
sscanf help. - 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)
+--- Thread: sscanf help. (/showthread.php?tid=317343)



sscanf help. - ReneG - 11.02.2012

I'm trying to make an /accept [name] command.
I have no errors when I compile, and my command works perfectly, but on my server window I get
Код:
[18:22:07] sscanf warning: Unknown format specifier 'j', skipping.
How can I fix this? This isn't really a major issue. I just really want to know how to compare strings with sscanf.
My code.
pawn Код:
CMD:accept(playerid,params[])
{
    new x_job[124];
    if(sscanf(params,"s[256]",x_job))
    {
        SendClientMessage(playerid,COLOR_GREY,"Usage: /accept [name]");
        SendClientMessage(playerid,COLOR_GREY,"Names: Job, Faction");
        return 1;
    }
    if(sscanf("job",params,"s[256]",x_job))
    {
    // I left out the rest of the command since the problem isn't within the command. It's mainly the above line.



Re: sscanf help. - 2KY - 11.02.2012

Sweet baby jesus, don't use 256, please!

pawn Код:
CMD:accept(playerid, params[])
{
    if(isnull(params)) {
        SendClientMessage(playerid,COLOR_GREY,"Usage: /accept [name]");
        return SendClientMessage(playerid,COLOR_GREY,"Names: Job, Faction");
    }
   
    if(strcmp(params, "job", true) == 0)
    {
        //Do the rest of your code
    }
    else return 0; //They typed in something other than "Job"
}



Re: sscanf help. - Sufyan - 11.02.2012

CMD:accept(playerid,params[])
{
new x_job[124];
if(sscanf(params,"s[256]",x_job))
{
SendClientMessage(playerid,COLOR_GREY,"Usage: /accept [name]");
SendClientMessage(playerid,COLOR_GREY,"Names: Job, Faction");
return 1;
}
if(!strcmp(x_job,"job",false)) //try this?
{


Re: sscanf help. - ReneG - 11.02.2012

So it is not possible to compare strings using sscanf?


Re: sscanf help. - 2KY - 11.02.2012

I'm honestly not sure, but it's common practice to compare them using strcmp. It's easier.


Re: sscanf help. - Psymetrix - 11.02.2012

You can compare strings with sscanf. I can't remember exactly how but this should work.

pawn Код:
if(!sscanf(params, "'job's[124]", x_job)) {
    // "Job" was found.
}



Re: sscanf help. - [ABK]Antonio - 11.02.2012

pawn Код:
if(!sscanf(params, "{'jobs'}"))
{
    //we would do code here
}
Is a way of comparing, however it isn't case sensitive