Gettok: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | |||
This function splits a string using the given seperating character and returns one part as a string. | This function splits a string using the given seperating character and returns one part as a string. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
string gettok ( string text, int | string gettok ( string text, int tokenNumber, int seperatingCharacter ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''text:''' The string that should be split | *'''text:''' The string that should be split | ||
*''' | *'''tokenNumber:''' Which token should be returned (1 for the first, 2 for the second, ..) | ||
*'''seperatingCharacter:''' The ASCII number of the character that seperates the strings (for example 44 for ',') | *'''seperatingCharacter:''' The ASCII number of the character that seperates the strings (for example 44 for ',') | ||
===Returns=== | ===Returns=== | ||
Returns ''string'' with the token if it exists, ''false'' otherwise. | Returns ''string'' with the token if it exists, ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example retrieves the startskin and endskin for spawning a player | This example retrieves the startskin and endskin for spawning a player | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- Put the string with the skins in a variable. Normally you would read it from a .map file or something. | -- Put the string with the skins in a variable. Normally you would read it from a .map file or something. | ||
Line 34: | Line 29: | ||
==See Also== | ==See Also== | ||
{{Area functions}} | |||
{{ | |||
[[Category:Incomplete]] | [[Category:Incomplete]] |
Revision as of 16:56, 10 August 2007
This function splits a string using the given seperating character and returns one part as a string.
Syntax
string gettok ( string text, int tokenNumber, int seperatingCharacter )
Required Arguments
- text: The string that should be split
- tokenNumber: Which token should be returned (1 for the first, 2 for the second, ..)
- seperatingCharacter: The ASCII number of the character that seperates the strings (for example 44 for ',')
Returns
Returns string with the token if it exists, false otherwise.
Example
This example retrieves the startskin and endskin for spawning a player
-- Put the string with the skins in a variable. Normally you would read it from a .map file or something. local skins = "20,30" -- Get the startskin and endskin (20 and 30) local startskin = gettok ( skins, 1, 44 ) local endskin = gettok ( skins, 2, 44 ) -- Get a random skin of the range local skin = randInt(tonumber(startskin),tonumber(endskin))