Gettok: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
{{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==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string gettok ( string text, int tokennumber, int seperatingCharacter )
string gettok ( string text, int tokenNumber, int seperatingCharacter )
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''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, ..)
*'''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===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns ''string'' with the token if it exists, ''false'' otherwise.
Returns ''string'' with the token if it exists, ''false'' otherwise.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example retrieves the startskin and endskin for spawning a player
This example retrieves the startskin and endskin for spawning a player
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<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==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Area functions}}
{{FunctionArea_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))

See Also

Template:Area functions