[Tutorial] Splitting data using sscanf - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (
https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Splitting data using sscanf (
/showthread.php?tid=416099)
Splitting data using sscanf -
Luis- - 16.02.2013
Splitting data using sscanf
I've only just found out how to do this, thanks to 2KY so I decided to make a small tutorial for those interested in doing this. If you do find any mistakes or anything that could be improved on, please do tell me!
Important
Before scripting there are a few essentials you'll need such as sscanf so please do get this if you haven't already before coding.
The Code Itself
This is a simple code, just to let you see what it could look like once you've finished coding it
Код:
if( !sscanf( params, "p<,>fff", xpos, ypos, zpos ) )
{
SetPlayerPos ( playerid, xpos, ypos, zpos );
}
This could simply be used for a teleport command, example: /goto 0.0 0.0 3.0 and you would be teleported to the center of the map.
Explanation of the Code
This is the part you'll need to read carefully in order to reach your goal of learning how to split data with sscanf.
Код:
if( !sscanf( params, "p<,>fff", xpos, ypos, zpos ) )
This is the first past of our example code, quite simple really, you've got the 'function' then the 'params' then the 'specifier' then the 'variables'.
Specifier
Here's something that might help you choose a specifier, thanks to ******.
Код:
Specifier(s) Name Example values
i, d Integer 1, 42, -10
c Character a, o, *
l Logical true, false
b Binary 01001, 0b1100
h, x Hex 1A, 0x23
o Octal 045 12
n Number 42, 0b010, 0xAC, 045
f Float 0.7, -99.5
g IEEE Float 0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E
u User name/id (bots and players) ******, 0
q Bot name/id ShopBot, 27
r Player name/id ******, 42
Conclusion
So after this, you should have more knowledge on splitting data using sscanf, hopefully you understood this topic, if not please post a reply
Thanks!
Re: Splitting data using sscanf -
RajatPawar - 16.02.2013
Try to explain what 'p<,>' means, or how you should decide on specifiers and when to use them.
Re: Splitting data using sscanf -
ReneG - 16.02.2013
This "tutorial" is self-explanatory if you bother to read the sscanf release topic...
Re: Splitting data using sscanf -
2KY - 16.02.2013
May wish to include a list of all available delimiters, and a list of possible uses for splitting data perhaps?
Other than that, it's quite simple and to the point, good job.
Re: Splitting data using sscanf -
Luis- - 16.02.2013
I've added a list of specifiers, will think of some more uses of splitting data. Thanks for the positive feedback.