Guide to the Godot game engine/Programming/GDScript/If statements

An "if" statement is a powerful piece of code. Every programming language has some kind of "if" statement. Valid examples are:
 * "if" statement

variable = variable == : variable < : (variable != {{Gdscript/string|5}) == ({{Gdscript/keyword|not} variable == {{Gdscript/string|5}): variable : ({{Gdscript/string|5}) variable: ( variable ==   )

Other rules to follow:

You must use indentation for a new line. You may put a statement on the same line as "if", but only if it is one line long:.

You cannot use "else if" syntax, like can be used in JavaScript, instead use the "elif" keyword.

A "value1 if something else value2" is a fast way to change a single argument in a function based on another value. It could be used like this:  Otherwise, an "if" statement must have indented code after it. Even if it is just.

Conditions in brackets are checked first, making  valid. If you do not use brackets, it reads the conditions left to right. So to check if  is a bool, then check if it is true (without risking an error if it is not a bool) use. If it is not a bool, the value is not checked to see if it is true.

See also: if conditions.