sscanf Bug -
Tagathron - 21.10.2013
I was scripting taxi job,and when i got to the /fare command part,i get bugs from sscanf.
There aren't compile errors/warnings just this bug.
So i used sscanf to print Driver [PLAYER NAME HERE] is now on duty.Fare [PRICE HE TYPED AFTER "/fare"] .
The bug is next:
-when i don't enter anything after fare it's supposed to print "USAGE: ..." but it prints that and
[MY NAME IG] is now on duty.Fare 0.
Prints the same thing when i type "/fare [SOME INTEGER HERE].
I checked multiple forums,and tested other peoples codes(which are like my one) and those codes also have bugs.
Here is the code:
Код:
CMD:fare (playerid, params[])
{
new price;
new string[128];
new taxistName[MAX_PLAYER_NAME];
if (sscanf(params, "i", price)) SendClientMessage(playerid, 0xFFF0F0, "USAGE : /fare [PRICE]");
GetPlayerName(playerid, taxistName, MAX_PLAYER_NAME);
format (string, sizeof(string), "Taxi driver %s is now on duty.Fare: %i .", taxistName,price);
SendClientMessageToAll(0xFFFFCC, string);
return 1;
}
Thanks in advance,i would really like to know how to solve this.
Re: sscanf Bug -
Konstantinos - 21.10.2013
pawn Код:
if (sscanf(params, "i", price)) return SendClientMessage(playerid, 0xFFF0F0, "USAGE : /fare [PRICE]");
You need to return a value to stop the rest of the code being executed.
Re: sscanf Bug -
BigGroter - 21.10.2013
pawn Код:
if(sscanf(params, "i", price)) return SendClientMessage(playerid, 0xFFF0F0, "USAGE : /fare [PRICE]");
Re: sscanf Bug -
Tagathron - 21.10.2013
Alright,thanks for replying and helping.
Re: sscanf Bug -
Pottus - 21.10.2013
In fact using sscanf() is a bad choice it's not needed at all.
Consider this.
pawn Код:
#define MIN_TAXI_PRICE 100
if (isnull(params)) return SendClientMessage(playerid, 0xFFF0F0, "USAGE : /fare [PRICE]");
else price = strval(params);
if(price < MIN_TAXI_PRICE) return SendClientMessage(playerid, 0xFFF0F0, "That price is too low");
Re: sscanf Bug -
Tagathron - 22.10.2013
Now it just sends "USAGE: /fare [PRICE]".
Код:
CMD:fare (playerid, params[])
{
new price;
new string[128];
new taxistName[MAX_PLAYER_NAME];
if (PlayerIsTaxiDriver[playerid]==1)
{
if (sscanf(params, "i", price)) return SendClientMessage(playerid, 0xFFF0F0, "USAGE : /fare [PRICE]");
GetPlayerName(playerid, taxistName, MAX_PLAYER_NAME);
format (string, sizeof(string), "Taxi driver %s is now on duty.Fare: %i .", taxistName,price);
SendClientMessageToAll(0xFFFFCC, string);
}
else if (PlayerIsTaxiDriver[playerid]==0)
{
SendClientMessage(playerid, CMD_ERROR, "You're not a taxi driver.");
}
return 1;
}