Garry's Mod Wiki


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


A compact '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".


An example of the differences between Lua's ternary operator and this function.

local myCondition = true local consequent = false local alternative = "Second string" print(myCondition and consequent or alternative) print(Either(myCondition, consequent, alternative))
Output: Second string


Page Links

Special Pages



Render Time: 83ms

DB GetPage 40
Generate Html 13
SaveChanges (1) 10
Render Body 0
Render Sidebar 18