[Tutorial] Splitting data using sscanf
#1

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!

Reply


Messages In This Thread
Splitting data using sscanf - by Luis- - 16.02.2013, 02:37
Re: Splitting data using sscanf - by RajatPawar - 16.02.2013, 02:40
Re: Splitting data using sscanf - by ReneG - 16.02.2013, 02:41
Re: Splitting data using sscanf - by 2KY - 16.02.2013, 02:42
Re: Splitting data using sscanf - by Luis- - 16.02.2013, 02:46

Forum Jump:


Users browsing this thread: 1 Guest(s)