Garry's Mod Wiki

Revision Difference

boolean#523636

<cat>Dev.Lua</cat>⤶ <cat></cat>⤶ A true or false value. Booleans are used to represent the outcome of a conditional statement. Provided below are some useful links: * [Booleans (PIL)](http://www.lua.org/pil/2.2.html) * <page text="If Statement Tutorial">Beginner_Tutorial_If_Then_Else</page> * [Logical Operators (PIL)](http://www.lua.org/pil/3.3.html) * [Operators tutorial](http://lua-users.org/wiki/OperatorsTutorial) <example> <description>Demonstrates how conditional statements treat booleans.</description> <code> if false then print("Value is false!") end if true then print("Value is true!") end </code> <output>Value is true!</output> </example> <example> <description>Inverting a boolean is often very useful. The easiest way to do that is to use the "not" operator.</description> <code> local bool = false if bool then print("Boolean is false, this code is not run!") end // Boolean is now being inverted ( false -&gt; true ) bool = not bool if bool then print("Boolean has been inverted and is now true!") end // This also works backwards. Note how "!" can be used in place of "not" bool = !bool if bool then print("Boolean is false again, and won't be printed!") end </code> <output>Boolean has been inverted and is now true!</output> </example>