|
|
#1 |
|
Big Clucker
![]() ![]() Join Date: May 2011
Posts: 52
Reputation: 0
|
Most (Or maybe all) people use sscanf like this method:
pawn Code:
But I feel like something confusing my mind. "params[]". I know it's the string after the command (right?) (f.e /command (params)). I have some question regarding this: 1- What happen if I put number/size in params? (f.e params[128]) 2- What if I do this (if(!sscanf(params,"s ",params)? Is it possible(I guess yes)? What is the advantage and disadvantage? 3- Is this method (if(!strcmp(string,"qwe"))) is faster than sscanf? Why? And how to convert this to sscanf? |
|
|
|
|
#2 |
|
Banned
![]() Join Date: May 2011
Location: Internet
Posts: 2,127
Reputation: 205
|
lol idk what will happen but i recommand you to leave it as it is now....
|
|
|
|
|
#3 |
|
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Dec 2009
Posts: 1,487
Reputation: 63
|
pawn Code:
|
|
|
|
|
#4 |
|
Godfather
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Feb 2010
Posts: 6,852
Reputation: 489
|
Okay, let me show you something...
pawn Code:
You will notice that you do not need to add the exclamation point (!) before calling sscanf. Above would be the proper way to use sscanf. In your given code example, using sscanf for such a thing is worthless. You could easily use the in-built isnull function which is inside the ZCMD include. An example: pawn Code:
Okay, let's answer your questions: 1) That would most likely give you an error when you attempt to compile- it is pointless to change the length of the params variable. 2) Again, doing such would be pointless simply because you don't need to use sscanf there. 3) I believe strcmp is actually faster than using sscanf because it's already an in-built function. Also keep in mind that you cannot use the sscanf syntax with strcmp- it doesn't pick up on the differences between u, i/d, s, etc... When using strcmp it is to compare two strings, sscanf is used to extract data from a string. I hope this has answered your questions. I would recommend reading the sscanf release thread before attempting to use it inside your mode. |
|
|
|
|
#5 | |||
|
Big Clucker
![]() ![]() Join Date: May 2011
Posts: 52
Reputation: 0
|
@willsuckformoney that's not what I mean.
@RealCop228: I already read the topic from ages. Quote:
pawn Code:
Quote:
Quote:
|
|||
|
|
|
|
#6 |
|
Gangsta
![]() ![]() ![]() ![]() Join Date: Apr 2011
Posts: 805
Reputation: 136
|
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:
|
|
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Tutorial] Explanation for sscanf2 and ZCMD | admantis | Tutorials | 11 | 17/04/2012 04:11 PM |
| zcmd/sscanf2 | Freddi-25 | Help Archive | 3 | 11/06/2011 11:27 PM |
| ZCMD & sscanf2 problem | pantelimonfl | Help Archive | 4 | 12/03/2011 05:10 PM |
| Player-Problem with Sscanf2 and ZCMD | dUDALUS | Help Archive | 2 | 09/01/2011 10:41 AM |
| /kick command with zcmd & sscanf2 | mrcoolballs | Help Archive | 6 | 24/08/2010 01:32 PM |