> For the complete documentation index, see [llms.txt](https://tchat.tect.host/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tchat.tect.host/general/actions/conditionals.md).

# Conditionals

Conditional actions allow you to execute different actions depending on whether a condition is true or false.

***

## \[IF]

<pre class="language-yaml"><code class="lang-yaml"><strong>actions:
</strong><strong>- "[IF] {player} == 'TectHost'"
</strong>- "[MESSAGE] Hello!"
- "[ENDIF]"
</code></pre>

The actions between `[IF]` and `[ENDIF]` are only executed if the condition evaluates to `true`.

## \[ELSE IF]

```yaml
actions:
- "[IF] {player} == 'TectHost'"
- "[MESSAGE] Hello TectHost!"
- "[ELSE IF] %vault_eco_balance% >= '1000'"
- "[MESSAGE] You are rich!"
- "[ENDIF]"
```

`[ELSE IF]` is only evaluated if every previous condition in the same block was false.

You can have as many `ELSE IF` blocks as you want.

## \[ELSE]

```yaml
actions:
- "[IF] {player} == 'TectHost'"
- "[MESSAGE] Hello TectHost!"
- "[ELSE]"
- "[MESSAGE] Hello everyone else!"
- "[ENDIF]"
```

The `ELSE` block is executed only if none of the previous conditions matched.

Only one `ELSE` block is allowed per `IF`.

## \[ENDIF]

```yaml
actions:
- "[ENDIF]"
```

Marks the end of the conditional block.

Every `[IF]` must have a matching `[ENDIF]`.

## Nested Actions

```yaml
actions:
  - "[IF] {player} == 'TectHost'"
  - "[MESSAGE] Welcome!"

  - "[IF] %vault_eco_balance% >= '1000'"
  - "[MESSAGE] You're also rich!"
  - "[ENDIF]"

  - "[ENDIF]"
```

Nested `IF` blocks work independently and must each have their own matching `[ENDIF]`.

## Example

```yaml
actions:
  - "[IF] {player} == 'TectHost'"
  - "[MESSAGE] <green>Welcome back, owner!"

  - "[IF] %vault_eco_balance% >= '100000'"
  - "[MESSAGE] <gold>You have over $100,000!"
  - "[ELSE IF] %vault_eco_balance% >= '10000'"
  - "[MESSAGE] <yellow>You have over $10,000."
  - "[ELSE]"
  - "[MESSAGE] <gray>You should earn some more money."
  - "[ENDIF]"

  - "[ELSE IF] %player_level% >= '100'"
  - "[MESSAGE] <aqua>You're a high-level player!"

  - "[IF] %player_world% == 'world_nether'"
  - "[MESSAGE] <red>Be careful in the Nether!"
  - "[ELSE]"
  - "[MESSAGE] <green>Enjoy your adventure!"
  - "[ENDIF]"

  - "[ELSE IF] %vault_eco_balance% >= '1000'"
  - "[MESSAGE] <yellow>You have at least $1,000."

  - "[ELSE IF] %player_ping% >= '200'"
  - "[MESSAGE] <red>Your connection seems slow."

  - "[ELSE]"
  - "[MESSAGE] <gray>Welcome to the server!"
  - "[ENDIF]"

  - "[MESSAGE] <white>This message is always executed."
```
