sscanf - optional number? -
Jack_Leslie - 07.10.2011
How do you have an optional number with sscanf?
I have,
pawn Код:
new action[128], item[128], amount;
if(sscanf(params, "s[128]z[128]d", action, item, amount))
{
SendClientMessage(playerid, COLOR_GREY, "* Usuage: /car [syntax]");
SendClientMessage(playerid, COLOR_GRAD2, "* Syntax: Check");
SendClientMessage(playerid, COLOR_GRAD3, "* Syntax: Put - pot crack mats weapon");
SendClientMessage(playerid, COLOR_GRAD4, "* Syntax: Get - pot crack mats weapon");
return 1;
}
And then,
pawn Код:
if(strcmp(action, "check") == 0)
{
if(!amount)
{
new pot, crack, mats, gun1, gun2, gun3;
pot = CarInfo[car][vPot], crack = CarInfo[car][vCrack], mats = CarInfo[car][vMats];
SendClientMessage(playerid, COLOR_GREY, "__________ Car Storage __________");
format(string, sizeof(string), "Crack: %d - Pot: %d - Materials: %d", crack, pot, mats);
SendClientMessage(playerid, COLOR_GRAD2, string);
}
return 1;
}
But if I do /car check then it doesn't work..
Re: sscanf - optional number? -
[MWR]Blood - 07.10.2011
pawn Код:
if(sscanf(params, "S[128]Z[128]D", action, item, amount))
Just put caps on the param(s) that you want to be optional.
Re: sscanf - optional number? -
Jack_Leslie - 07.10.2011
Cheers mate, that worked. How do I check if nothing is entered in the option string if I want something to be entered?
I tried:
pawn Код:
if(!strlen(item)) return SendClientMessage(playerid, COLOR_GREY, "* Usuage: /car put [item] [amount]");
But it didn't work, I also tried just if(!item) but that didn't work neither.
Re: sscanf - optional number? -
iggy1 - 07.10.2011
You mean you want default values on the params? or just check if params is null?
Re: sscanf - optional number? -
[MWR]Blood - 07.10.2011
Use
Re: sscanf - optional number? -
iggy1 - 07.10.2011
Default values are enclosed in parentheses.
pawn Код:
if(sscanf(params, "S[128](default string)S[128](another string)D(500)", action, item, amount))
Result is; action = "default string", item = "another string" and amount = 500. If no params were entered. Also assuming your using the plugin.
Quote:
Originally Posted by [MWR]Blood
|
He is already using sscanfs inbuilt null check in his code...
Re: sscanf - optional number? -
Jack_Leslie - 07.10.2011
Quote:
Originally Posted by iggy1
Default values are enclosed in parentheses.
pawn Код:
if(sscanf(params, "S[128](default string)S[128](another string)D(500)", action, item, amount))
Result is; action = "default string", item = "another string" and amount = 500. If no params were entered. Also assuming your using the plugin.
|
action = needed string
item = optional string
amount = needed value if item is entered
I get undefined symbol on isnull, why? :S
Re: sscanf - optional number? -
iggy1 - 07.10.2011
Quote:
Originally Posted by Jack_Leslie
action = needed string
item = optional string
amount = needed value if item is entered
I get undefined symbol on isnull, why? :S
|
DW your sscanf line IS checking if params is null. You dont need to use "isnull" in this case. BTW which command processor are you using?
Re: sscanf - optional number? -
Jack_Leslie - 07.10.2011
Quote:
Originally Posted by iggy1
DW your sscanf line IS checking if params is null. You dont need to use "isnull" in this case.
|
Oh right okay so I'm not using isnull, however, if I put a action item and no amount, the default amount is 114, but it should send the message syntax: /car put or whatever I want to send?