util.StringToType

From Garry's Mod
Jump to: navigation, search
 util.StringToType( )

Contents

Description

Converts a string to the specified type.

This can be useful when dealing with ConVars.

Arguments

string str

The string to convert

Arguments

string typename

The type to attempt to convert the string to. This can be vector, angle, float, int, bool, or string (case insensitive).

Returns

any

The result of the conversion, or nil if a bad type is specified.

Examples

Example

Creates a vector from a string representation.

local vec = util.StringToType("5 6 75", "Vector")

Output:

A vector with components (5, 6, 75)
Personal tools
Navigation