SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 18/07/2011, 02:05 AM   #1
letters
Big Clucker
 
Join Date: May 2011
Posts: 52
Reputation: 0
Default sscanf2 and zcmd

Most (Or maybe all) people use sscanf like this method:
pawn Code:
CMD:a(playerid,params[])
{
   new string[128];
   if(!sscanf(params,"s ",string)
   .............

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?
letters is offline  
Old 18/07/2011, 02:08 AM   #2
xkirill
High-roller
 
xkirill's Avatar
 
Join Date: May 2011
Location: In a box infront of your house stealing your WiFi
Posts: 2,494
Reputation: 287
Default Re: sscanf2 and zcmd

lol idk what will happen but i recommand you to leave it as it is now....
__________________
KrustyGames.com
Project SAMP Fast & Furious - Coming soon
"by rating your skills, you're limiting yourself." - Kaperstone
xkirill is offline  
Old 18/07/2011, 02:18 AM   #3
willsuckformoney
High-roller
 
willsuckformoney's Avatar
 
Join Date: Dec 2009
Posts: 1,505
Reputation: 65
Default Re: sscanf2 and zcmd

pawn Code:
if(sscanf(params, "s", params[2]))
That is already the error line. Meaning if you don't enter something for the params (The string or whatever) then it will not let you continue
__________________
Fuck the system.
willsuckformoney is offline  
Old 18/07/2011, 02:20 AM   #4
RealCop228
Godfather
 
Join Date: Feb 2010
Location: Springboro, OH
Posts: 8,269
Reputation: 670
Default Re: sscanf2 and zcmd

Okay, let me show you something...

pawn Code:
CMD:something(playerid, params[])
{
        new id, value1, value2; // defining the variables for sscanf
    if(!IsPlayerAdmin(playerid))
        return false;
    if(sscanf(params, "udd", id, value1, value2))
        return // Send syntax message.

    // More stuff here...
    return 1;
}

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:
if(isnull(params)) // do something, the params are null (empty)


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.
__________________
Putting [URGENT] in the thread title stops me from opening the thread. Nobody else's problem on this forum is more important that another person's. Try not to be self-centered!
RealCop228 is offline  
Old 18/07/2011, 02:41 AM   #5
letters
Big Clucker
 
Join Date: May 2011
Posts: 52
Reputation: 0
Default Re: sscanf2 and zcmd

@willsuckformoney that's not what I mean.

@RealCop228:

I already read the topic from ages.

Quote:
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.
AFAIK "!" isn't useless.
pawn Code:
if(sscanf(params,"s[129] ",string)) return SendClientMessage(playerid,xxx,"This message will sent if player isn't type any params/wrong params.");
if(!sscanf(params,"s[129] ",string)) return SendClientMessage(playerid,xxx,"This message will sent if player type any correct params.");

Quote:
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:
I'm just sorting about a simple method.

Quote:
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.
It didn't give me any error. I just don't know why there's no size in params (Actually Idk why every funtion don't have size like OnPlayerCommandText(playerid,text[])
letters is offline  
Old 18/07/2011, 06:38 AM   #6
Bakr
High-roller
 
Join Date: Apr 2011
Posts: 1,023
Reputation: 196
Default Re: sscanf2 and zcmd

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" );
Bakr is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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 06:10 PM
Player-Problem with Sscanf2 and ZCMD dUDALUS Help Archive 2 09/01/2011 11:41 AM
/kick command with zcmd & sscanf2 mrcoolballs Help Archive 6 24/08/2010 01:32 PM


All times are GMT. The time now is 11:44 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.