SA-MP Forums Archive
Help sscanf2 and optional variables - 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: Help sscanf2 and optional variables (/showthread.php?tid=620189)



Help sscanf2 and optional variables - Jose_grana - 27.10.2016

My idea it Create variable UN with an optional second command. Command left:

pawn Код:
CMD:comando(playerid, params[])
{
    if(sscanf(params, "s[32]I(5)", params[0], params[1]))
    {

        SendClientMessage(playerid, -1, "USO: /comando [Opciуn] ");
        SendClientMessage(playerid, -1, "Primera, Segunda, Tercera, Cuarta");
        return 1;
    }
    if(strcmp(params[0],"primera",true) == 0)
    {
        if(params[1] == 5) return       SendClientMessage(playerid, -1, "/comando  primera [Cantidad]");
        SendClientMessage(playerid, -1, "Crear");
   
    }
    else if(strcmp(params[0],"segunda",true) == 0)
    {

        SendClientMessage(playerid, -1, "segunda");
    }
    else if(strcmp(params[0],"tercera",true) == 0)
    {

    }
    else if(strcmp(params[0],"cuarta",true) == 0)
    {

    }  
    return 1;
}
The idea is that by using / first command will require the second parameter but use / second command no.
I hope I made myself clear.

+1 I solve it.

sorry my bad Inglйs


Re: Help sscanf2 and optional variables - Vince - 27.10.2016

Don't reuse the "params" variable. This is prone to all kinds of nasty out-of-bounds errors and other nasty bugs. Create two separate variables and use those. Much cleaner, much less prone to errors.


Respuesta: Help sscanf2 and optional variables - Jose_grana - 30.10.2016

Help please.