table.HasValue

From GMod Wiki

Revision as of 17:32, 30 August 2011 by Wizard (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax table.HasValue( Table table, Var value )
Where is this used?
Description:
Checks if a table has a value.
Returns: Boolean
Part of Library: Table
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Table.HasValue]Table.HasValue [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionChecks if a table has a value.
Used onNewerShared.png
Code
local test_table = {"cheese", "milk", "cookies"}
 
if table.HasValue( test_table, "milk" ) then // Checks if the table has "milk" in it
	print( "We have milk" )
else
	print( "We don't have milk" )
end
Output
We have milk


Additional Notes

Table = {"String", "Table"}
table.HasValue(Table, "String") -- This will work, as both data types are strings
table.HasValue(Table, 1) -- This will not work, as it's comparing a number with a string.


See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox