Garry's Mod Wiki

util.StringToType

any util.StringToType( string str, string typename )

Description

Converts a string to the specified type.

This can be useful when dealing with ConVars.

Arguments

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

Returns

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

Example

Creates a vector from a string representation.

local vec = util.StringToType("5 6 75", "Vector")
Output: A vector with components (5, 6, 75)

Page Links


Special Pages


Wikis

?

Render Time: 33ms

DB GetPage 4
Generate Html 6
SaveChanges (1) 8
Render Body 0
Render Sidebar 12