> ## Documentation Index
> Fetch the complete documentation index at: https://entities.lodemc.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Flow Control

> delay, skill, if, loop, while, switch and random skills: sequences and decisions.

Flow control turns a list of lines into a sequence and a set of decisions: pause between lines, branch on conditions, loop, and pick random outcomes. Every mechanic here is listed in [Skills & Flow](https://entities.lodemc.net/mechanics-flow.md); this page shows how to use them.

## delay

Pauses the **rest of the current skill**, then carries on. This is the backbone of telegraphed attacks.

```yaml theme={null}
  smash:
  - particlering{p=flame;radius=5;points=48} @self   # warn
  - delay 0.5s                                       # wind up
  - damage{amount=10} @playersRadius[4]              # hit
```

`delay` and `wait` are the same mechanic. A bare number is ticks: `delay 20`. A `delay` inside a called skill pauses that skill only, not whatever called it.

To delay just **one** line without pausing the ones after it, give that line the `delay` [option](https://entities.lodemc.net/line-options.md) instead: `damage{a=5;delay=10}`.

`wait{until=…}` waits for a condition instead of a time:

```yaml theme={null}
- wait{until=isNight;interval=20;timeout=6000}
- skill{s=night_form}
```

## skill

Runs another [skill](https://entities.lodemc.net/named-effects.md). Its lines inherit this line's targets unless they set their own `@`.

```yaml theme={null}
- skill{s=smash} +onHurt @trigger
- run smash +onHurt @trigger                       # the short form
- skill{s=fireball;damage=12} +onAttack @target     # with a parameter: <skill.damage> is 12 inside it
```

## if

Runs one body when a condition holds, optionally another when it doesn't.

| Option | What it is |
| - | - |
| `cond` | The condition. See [Conditions](https://entities.lodemc.net/conditions.md#combining-them). |
| `then` | Body to run when it holds. |
| `else` | Optional body when it doesn't. |

```yaml theme={null}
- if{cond=var.phase >= 2;then=enrage;else=calm} +onHurt @trigger
- if{cond=random < 0.3;then=rare_drop}          +onDeath @self
```

For a one-line gate, an inline condition is shorter: `- skill{s=enrage} +onHurt ?health{h=<50%}`. See [Line Options](https://entities.lodemc.net/line-options.md#inline-conditions).

## loop

Runs a body a fixed number of times.

| Option | What it is |
| - | - |
| `effect` | The body to run. |
| `times` | Required. Iterations, capped at 1000. |
| `every` | Optional. One iteration per this many ticks. Omit for back-to-back. |

```yaml theme={null}
- loop{effect=ring_blast;times=3;every=10} @self
```

## while

Checks a condition on an interval and runs the body while it holds. It checks first, then runs.

| Option | Default | What it is |
| - | - | - |
| `cond` | required | The condition. |
| `effect` | required | The body to run each round. |
| `every` | `1s` | Time between checks. Minimum 1 tick. |
| `max` | `100` | Safety cap on iterations, up to 10000. |

```yaml theme={null}
- while{cond=var.charging;effect=charge_tick;every=5;max=200} @self
```

## Bodies: named effects or inline blocks

A body (`then`, `else`, `effect`) is either a **skill id**, resolved on the mob first exactly like `skill`, or an **inline block** `{stmt;stmt;…}`:

* Statements are full lines, a mechanic plus an optional `@targeter`, separated by `;`.
* Blocks **nest**: a statement can be another `if`, `loop` or `while` with its own block.
* A block may span **several lines**, and continuation lines may start with `- `. They are joined before YAML reads the file.

```yaml theme={null}
- if{cond=random < 0.5;then={narrate "&dheads!";sound{s=block.bell.use}};else={narrate "&dtails"}}
- if{cond=var.phase >= 2;then={
  - narrate "&cThe boss is enraged!" @playersRadius[20]
  - setspeed{speed=0.45} @self
  - glow{glowing=true} @self
  };else=calm_down}
```

Rules for blocks:

* No triggers inside a block. The trigger belongs to the outer line.
* No comments inside a multi-line block.
* A malformed or empty block fails the whole line at load time, and [`/le debug`](debug) says where.
* Prefer a named skill when the body should be reusable. Blocks are for short one-off branches.

`skill` takes MythicMobs' inline list instead: `skill{s=[ - damage{a=4} - ignite ]}`.

## switch

Picks a skill by value:

```yaml theme={null}
- switch{condition=<caster.var.phase>;cases=case 1=phase_one case 2=phase_two case default=idle}
```

## randomskill and randommessage

```yaml theme={null}
- randomskill{skills=slam,fire_breath,summon_wave} +onAttack @target
- randommessage{messages=&7Hello!|&7Greetings.|&7Oh, you again.} +onInteract @trigger
```

## Behaviour notes

* A branch or loop body runs with the caller's context: the same targets (unless its lines set their own) and the same `skill.` variables, so loop counters made with `var{…}` work across iterations.
* A `delay` inside a looped body pauses **that iteration only**, not the loop's schedule.
* Spaced `loop` and `while` stop early if the mob dies or despawns. `while`'s `max` is a hard cap against infinite loops.
* `cancelskill` stops the rest of the current skill.

## The counter pattern

```yaml theme={null}
  effects:
  - var{n=0}                                          +onInteract @trigger
  - while{cond=var.n < 5;effect=step;every=10} @self  +onInteract
  step:
  - var{n+=1}
  - actionbar{message=&6charge <var.n> of 5} @playersRadius[16]
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.