SSCANF check within SSCANF check
#1

Using a previous thread of mine I tried to integrate the same method into a different command, right now I've got this:


Код:
CMD:editservercar(playerid,params[])
{
	SendCMD(playerid, params);
	if(pData[playerid][pAdmin] >= 2)
	{
		if(!IsPlayerInAnyVehicle(playerid)) return SendErrorMessage(playerid, "You must be inside of a vehicle to do this.");
		new section[20];
		if(sscanf(params, "s[20]", section))
		{
			SendUsageMessage(playerid, "/editservercar [section]");
			SendClientMessage(playerid, COLOR_LIGHTBLUE, "Sections:{FFFFFF} Position | Faction | Job | Color1 | Color2 | Siren");
			return 1;
		}
		else
		{
			if(strmatch(section, "position"))
			{
				... code here that works that doesnt have a 2nd SSCANF in it
			}
			else if(strmatch(section, "faction"))
			{
				new factionid;
				if(sscanf(params, "s[20]i", section, factionid)) return SendUsageMessage(playerid, "/editservercar faction [factionid] (0-19)");
				SendClientMessage(playerid, COLOR_LIMEGREEN, "debug 2nd sscanf");
			}
Using a little bit of debugging I get this:

(SendCMD simply shows the full cmd typed)



What am I doing wrong?
Reply
#2

"faction 1" is considered as a whole string on your first sscanf usage. You can have optional parameter on sscanf to accept an integer in case if it's given.
pawn Код:
sscanf(params, "s[20]I("#INVALID_PLAYER_ID")", section, factionid)

//factionid will be INVALID_PLAYER_ID if "/editservercar faction" is executed.
//Will hold any other value if "/editservercar faction <somevalue>" is executed.
Another way is using SSCANF_QUIET to simply ignore any integer value after "faction" in your first usage. But I would recommend the first way because you don't have to use sscanf twice then, as per your current code.
pawn Код:
sscanf(params, "?<SSCANF_QUIET=1>s[20]{i}", section)
Reply
#3

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
"faction 1" is considered as a whole string on your first sscanf usage. You can have optional parameter on sscanf to accept an integer in case if it's given.
pawn Код:
sscanf(params, "s[20]I("#INVALID_PLAYER_ID")", section, factionid)

//factionid will be INVALID_PLAYER_ID if "/editservercar faction" is executed.
//Will hold any other value if "/editservercar faction <somevalue>" is executed.
Another way is using SSCANF_QUIET to simply ignore any integer value after "faction" in your first usage. But I would recommend the first way because you don't have to use sscanf twice then, as per your current code.
pawn Код:
sscanf(params, "?<SSCANF_QUIET=1>s[20]{i}", section)
Your first approach worked out for me, cheers!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)