sscanf2 and zcmd
#6

The reason there isn't a size for params is that it can't be determined at compilation time how long the string passed to the function will be, as a player could type an any 'params' into that command.

1. If you mean adding it into the function that you create the command with, then any command you type more than that many characters with won't be parsed/read correctly. The string will be cut off at some point, the max size that you set it to. If you are referring to the sscanf function, then I would assume it would only parse data after that cell in the string.

2. I believe that would work. However, in the situation you provided, it would be useless as the string is already in the params variable (there is no reason to use sscanf regardless of what param will hold if you have only one argument). I can't really see a downside of using params variable to store data you extracted from it in the first place, unless sscanf extracts the characters one-by-one. So you should be fine using it. Test it and see for yourself! (Note: You will need to always put string parsing at the end of the sscanf line unless there is some type of delimiter or a specified length, or else it won't be able to tell the start and end of one string from the other)

3. That isn't a answerable question as strcmp( ) function compares two strings, nothing more. sscanf( ) function parses (extracts) data from a given string. If you mean which method is faster - using OnPlayerCommandText callback or ZCMD - then ZCMD is faster, especially if you have many commands in your gamemode. Reason being, ZCMD calls a function directly to call the function rather than compare x (number of commands) strings to see if it's a valid string (inside the OnPlayerCommandText callback).

As far as the explanation mark, there's no difference. It depends on your style of coding to which method you use. See as both are the same:
pawn Code:
if( sscanf( params, "iii", x, y, z ) return SendClientMessage( playerid, 0xFFFFFFFF, "Invalid params" );

if( !sscanf( params, "iii", x, y, z )
{
   // code
}
else return SendClientMessage( playerid, 0xFFFFFFFF, "Invalid params" );
Reply


Messages In This Thread
sscanf2 and zcmd - by letters - 18.07.2011, 02:05
Re: sscanf2 and zcmd - by Kaperstone - 18.07.2011, 02:08
Re: sscanf2 and zcmd - by willsuckformoney - 18.07.2011, 02:18
Re: sscanf2 and zcmd - by Scenario - 18.07.2011, 02:20
Re: sscanf2 and zcmd - by letters - 18.07.2011, 02:41
Re: sscanf2 and zcmd - by Bakr - 18.07.2011, 06:38

Forum Jump:


Users browsing this thread: 1 Guest(s)