Garry's Mod Wiki


any Either( any condition, any truevar, any falsevar )


An 'if then else'. This is almost equivalent to (condition and truevar or falsevar) in Lua. The difference is that if truevar evaluates to false, the plain Lua method stated would return falsevar regardless of condition whilst this function would take condition into account.


1 any condition
The condition to check if true or false.
2 any truevar
If the condition isn't nil/false, returns this value.
3 any falsevar
If the condition is nil/false, returns this value.


1 any
The result.


The following two print statements have identical results.

local ply = Entity( 1 ) print( "Player " .. Either( ply:IsAdmin(), "is", "is not" ) .. " an admin" ) print( "Player " .. ( ply:IsAdmin() and "is" or "is not" ) .. " an admin" )
Output: If Player 1 is admin, it will print "Player is an admin".


Plain Lua alias version.

print("You are: "..( LocalPlayer():Alive() and "alive" or "dead" )) // conditional: print( "Halflife? "..( (LocalPlayer():Health()==50) and "halflife" or "not halflife") )
Output: You are alive

Halflife? not halflife

Page Links

Special Pages



Render Time: 49ms

DB GetPage 3
Generate Html 19
SaveChanges (1) 12
Render Body 0
Render Sidebar 12