Gettok

From Multi Theft Auto: Wiki
Revision as of 18:20, 17 August 2007 by Arc (talk | contribs)
Jump to navigation Jump to search

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 separatingCharacter )

Required Arguments

  • text: The string that should be split
  • tokenNumber: Which token should be returned (1 for the first, 2 for the second, ..)
  • separatingCharacter: The ASCII number of the character that seperates the strings (for example 44 for ',')

Returns

Returns the token if it exists, false otherwise.

Example

Click to collapse [-]
Server

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