Persistent SSCANF Issue, Please help me resolve this once and for all.
#1

The first SSCANF you can see works, but the second does not at all. It's rather irritating. Could someone give me some pointers as to why it will not work, i've tried everything in the book.


pawn Код:
if(sscanf(params, "s[32]",usage))
    {
        SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk [usage]");
        SendClientMessage(playerid, COLOUR_GREY, "Usages: Store, Get, View");
    }
            printf("USAGE: %s", usage);
    VehicleSQLID[vehicleid] = MySQL_GetValue(VehicleSQLID[vehicleid], "id", "vehicles");
    if(vehicleid == TrunkOpened[playerid])
    {
        if(!strcmp(usage, "store", true))
        {
            printf("USAGE: %s", usage);
            if(sscanf(usage, "s[24]",item))// This will not send the client messages.
            {
                SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store [item]");
                SendClientMessage(playerid, COLOUR_GREY, "Available Items: Weapon, Weed, Cocaine, Money, Armour");
            }
                printf("USAGE: %s", usage);
                printf("ITEM: %s", item);
Reply
#2

Don't the prints reveal something?

sscanf("store cocaine", "s[32]", usage) will return "store". After that, you use sscanf(usage, "s[24]", item) and there's no way that the item can be "weapon" or anything like that, since you're actually doing sscanf("store", "s[24]", item)?

Am I wrong here?

So to go further on, I assume the possible usages of your command are:
/trunk store item
/trunk get item
/trunk view

This can be resolved by a simple sscanf!
pawn Код:
new option[32], item[32];
if(sscanf(params, "s[32]S(*)[32]", option, item))
{
        SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk [usage]");
        SendClientMessage(playerid, COLOUR_GREY, "Usages: Store, Get, View");
        return true;
}
if(!strcmp(option, "store", true))
{
    if(item[0] == '*')
    {
        SendClientMessage(playerid, COLOUR_GREY, "USAGE: /trunk store [item]");
        SendClientMessage(playerid, COLOUR_GREY, "Available Items: Weapon, Weed, Cocaine, Money, Armour");
        return true;
    }
    printf("Yay, %s!", item);
}
Reply
#3

I've told him to try something similar already but he's stuck on trying to use sscanf...
Reply
#4

as already pointed out, the optional sscanf S()[] specifier is a neat way to do this:
pawn Код:
if(sscanf(params, "s[32]S()[32]",usage,item))
{
    SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk [usage]");
    SendClientMessage(playerid, COLOUR_GREY, "Usages: Store, Get, View");
}
printf("USAGE:%s ITEM:%s", usage,item);
VehicleSQLID[vehicleid] = MySQL_GetValue(VehicleSQLID[vehicleid], "id", "vehicles");
if(vehicleid == TrunkOpened[playerid])
{
    if(!strcmp(usage, "store", true))
    {
        if(!strcmp(item, "weapon", true))
        {
        }
        else if(!strcmp(item, "weed", true))
        {
        }
        else if(!strcmp(item, "cocaine", true))
        {
        }
        else if(!strcmp(item, "money", true))
        {
        }
        else if(!strcmp(item, "armor", true))
        {
        }
    }
    else if(!strcmp(item, "get", true)
    {
        if(!strcmp(item, "weapon", true))
        {
        }
        else if(!strcmp(item, "weed", true))
        {
        }
        else if(!strcmp(item, "cocaine", true))
        {
        }
        else if(!strcmp(item, "money", true))
        {
        }
        else if(!strcmp(item, "armor", true))
        {
        }
    }
    else if(!strcmp(item, "view", true)
    {
        if(!strcmp(item, "weapon", true))
        {
        }
        else if(!strcmp(item, "weed", true))
        {
        }
        else if(!strcmp(item, "cocaine", true))
        {
        }
        else if(!strcmp(item, "money", true))
        {
        }
        else if(!strcmp(item, "armor", true))
        {
        }
    }
    else
    {
        SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store [item]");
        SendClientMessage(playerid, COLOUR_GREY, "Available Items: Weapon, Weed, Cocaine, Money, Armour");
    }
by creating a custom specifier which recognizes a string, and returns a numerical value (1 for weapon, 1 for weed etc), this spaghetti like snippet would look better
not tested btw...
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)