# If-Statements

TIP

If statements are useful to run code only if a certain condition is TRUE, otherwise the code won't be run.

# If-Statement Format

You can use if statements in either one line of code, or multiple lines, the format for 1 line of code is:

if (<condition>) { #Code }

And for multiple lines:

if (<condition>) {
   # Code
}

If you want some code to run if the if-statement was FALSE, then you can use else, here's how it would look like:

if (<condition>) {
   # Code
} else {
    # Code to run if the condition was FALSE
}

For 1 line of code, do this:

if (<condition>) {
   # Code
} else { # Code to run if the condition was FALSE }

You can also use elseif which basically runs another if-statement if the one before it was FALSE, it woud look like this:

if (<condition>) {
   # Code
} elseif (<condition>) {
   # Code
}

For 1 line of code, do this:

if (<condition>) {
   # Code
} elseif (<condition>) { # Code }

# Example

1: if ($player$ != 'Acsrel') {
2:    sendMessage($player$, 'This command can only be used by Acsrel.')
3:    exit()
4: } elseif ($health$ < 5 and $food$ < 5) {
5:    setHealth($player$, 20)
6:    setHunger($player$, 20)
7: } else { exit() }