Optional sscanf parameters -
MP2 - 20.10.2012
I know how sscanf optional parameters work - you have to provide a 'default' value or whatever, but how can I tell if a player passed that parameter or not? They could pass the default value..
Re: Optional sscanf parameters -
Babul - 20.10.2012
hm. if i remember right, with the pawn version of sscanf, i had to scan for 1 huge string, take a token, and pass the remaining inputdata to another (optional) string, and did that check again per token/string containing it. if i remember right, it was possible by checking if the optional (second) string was empty or not...
oh gawd, i found it

i wanted to use the vehicle color command to assign the other colors (second car and trailer) aswell, if not typed:
Код:
CMD:carcol(playerid,params[]){
new Col1,option[16],Col2,string[64];
if (sscanf(params,"dS[16]",Col1,option))
{
SendClientMessage(playerid,MSGCMDS_COLOR, "Usage: \"/CarCol <Col1> [Col2] [Col3 (=Trailer)]\"");
return 1;
}
else
{
//here a strlen, isnull, or whatever check?
if (sscanf(option,"d",Col2))
{
SendClientMessage(playerid,MSGINFO_COLOR, "Color1 will be the same as Color2.");
Col2=Col1;
}
new VehicleID=GetPlayerVehicleID(playerid);
ChangeVehicleColor(VehicleID,Col1,Col2);
SetGVarInt("VehCol1",Col1,VehicleID);
SetGVarInt("VehCol2",Col2,VehicleID);
format(string,sizeof(string),"Colors changed to %d - %d.",Col1,Col2);
SendClientMessage(playerid,MSGSUCC_COLOR,string);
new TrailerID;
TrailerID=GetVehicleTrailer(VehicleID);
if(TrailerID>0)
{
ChangeVehicleColor(TrailerID,Col1,Col2);
SetGVarInt("VehCol1",Col1,TrailerID);
SetGVarInt("VehCol2",Col2,TrailerID);
format(string,sizeof(string),"Trailer colors changed aswell.");
SendClientMessage(playerid,MSGSUCC_COLOR,string);
}
}
return 1;
}
argh, and there the string comparison was supposed to be, but instead its
if (sscanf(option,"d",Col2))
for checking for another optional parameter (if existing).
maybe it contains a hint into the right direction
Re: Optional sscanf parameters -
MP2 - 20.10.2012
Quote:
Originally Posted by ******
You can't really, the point of the defaults is to pick something they can't type, of course that isn't always possible. Sorry, just assume that if they typed a stupid value they're being stupid, and try make the message generic like "please enter a value between 0 and 27" - then it doesn't matter if what they typed was wrong or if they typed nothing.
|
It's not meant to return a message:
The command is /vcolor [color1] [color2]
If color2 isn't specified, it should be made the same as color1.
Would it be possible to use NaN? If not I guess -1 will do.
Re: Optional sscanf parameters -
MP2 - 20.10.2012
You're right, it doesn't matter. It just got my thinking about how to do it for in the future.