Issues with optional string on sscanf?
#1

pawn Код:
if(sscanf(params, "s[24]s[32]s[24]",usage,item,wepname))
    {
        SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store weapon [weapon name]");
        SendClientMessage(playerid, COLOUR_GREY, "Use /wepnames for a list of valid names.");
        return 1;
    }
It returns this:

pawn Код:
if(sscanf(params, "s[24]S(0)[32]S(0)[24]D(0)",usage,item, wepname, slot))
    {
        SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk [usage]");
        SendClientMessage(playerid, COLOUR_GREY, "Usages: Store, Get, View");
        return 1;//ok take me back to the place that's not working
    }
Any assistance would be appreciated.

I'm a little behind on remembering how optionals work!

Thanks for any response.
Reply
#2

You should really only put one optional string and it should be last parameter at that. I don't think you can put an optional string before another type of parameter or even multiple optional strings. If one those strings contains extra spaces sscanf will screw up because it doesn't know where it needs to split.
Reply
#3

How can I allow it to have a space? Also this happens. I've used the optionals before without issue.

This happens on a print.

pawn Код:
if(sscanf(params, "s[24]s[32]s[24]",usage,item, wepname))
                {
                    printf("usage %s, item %s, wepname %s", usage, item, wepname);
                    SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store weapon [weapon name]");
                    SendClientMessage(playerid, COLOUR_GREY, "Use /wepnames for a list of valid names.");
                    return 1;
                }
It returns 0 for wepname?
Reply
#4

So the behaviour is correct? I also ordered it correctly?

I checked, I no longer believe this is a SSCANF issue.
Reply
#5

Well, now the other functions don't seem to be working. It's a little strange, I apologise for the delay.

It's to do with the sscanf and I'm not entirely sure.

pawn Код:
if(sscanf(params, "s[24]S(0)[32]D(0)S(0)[12]",usage,item, slot, wepname))
    {
        SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk [usage]");
        SendClientMessage(playerid, COLOUR_GREY, "Usages: Store, Get, View");
        return 1;
    }
I see, thanks for the information regarding the specifier.

However, it does not complete any function within the command, stops after sscanf, but only after I re-wrote the weapons system adding another specifier.

pawn Код:
if(!strcmp(usage, "store", true))
        {
            printf("USAGE: %s", usage);
            if(sscanf(params, "s[24]s[32]",usage,item))
            {
                SendClientMessage(playerid, COLOUR_GREY, "Usage:/trunk store [item]");
                SendClientMessage(playerid, COLOUR_GREY, "Available Items: Weapon, Weed, Cocaine, Money, Armour");
                return 1;

            }
            if(!strcmp(item, "weed", true))
            {
                printf("%s - usage", usage);
                printf("%s - retrieved item", item);
                if(VehicleSQLID[vehicleid] > 0)
                    {
                        VehWeed[vehicleid] = MySQL_GetValue(VehicleSQLID[vehicleid], "VehWeed", "vehicles");
                        Weed[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "weed", "accounts");
                    }
                printf("%d - got weed amount", Weed[playerid]);
                if(sscanf(params, "s[24]s[32]d",usage,item,slot))
                {
                    SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk store weed [amount]");
                    return 1;

                }
                if(slot > Weed[playerid]) return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much weed.");
                printf("%d - amount", slot);
                VehWeed[vehicleid] += slot;
                Weed[playerid] -= slot;
                if(VehicleSQLID[vehicleid] > 0)
                {
                    MySQL_SetInteger(VehicleSQLID[vehicleid], "VehWeed", VehWeed[vehicleid], "vehicles");
                    MySQL_SetInteger(PlayerSQLID[playerid], "Weed", Weed[playerid], "accounts");
                }
                format(string, sizeof(string), "You have stored a %d gram(s) of weed in your vehicle's trunk.", slot);
                SendClientMessage(playerid, COLOUR_BLUE, string);
                format(string, sizeof(string), "* %s has stored some drugs in the vehicle's trunk", GetNameEx(playerid));
                ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
            }
For instance, that was working and now it does not.

Forums messed up the code......

This is what the sscanf used to look like.

pawn Код:
if(sscanf(params, "s[24]S(0)[32]D(0)",usage,item, slot))
    {
        SendClientMessage(playerid, COLOUR_GREY, "Usage: /trunk [usage]");
        SendClientMessage(playerid, COLOUR_GREY, "Usages: Store, Get, View");
        return 1;//ok take me back to the place that's not working
    }
The new one asks for a string.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)