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

# Variables

> Let mobs remember things: writing, reading, scopes and placeholders.

Variables let mobs remember things: hit counters, phase numbers, charge states. They're what turn a bag of effects into a boss with memory.

## Writing variables

Use `var{...}`. It reads like code, and several assignments can share one block:

```yaml theme={null}
- var{hits+=1}                # add 1 (missing counts as 0)
- var{shield-=5}              # subtract
- var{phase=2}                # set a number
- var{title=The Angry One}    # set text
- var{tmp=}                   # unset (empty value)
- var{global.kills+=1}        # another scope via prefix
```

## Reading variables

Anywhere text is shown (`message`, `actionbar`, `title`, `setname`, `command`), use `<var.name>`:

```yaml theme={null}
- actionbar{message=&eHits: <var.hits>} #onHurt @target
```

An unset variable resolves to empty. Numbers print without a trailing `.0`. Names are case-insensitive.

## Scopes

Where a variable lives. No prefix means the mob itself:

| Prefix                               | Stored on                              | Lifetime                                      |
| ------------------------------------ | -------------------------------------- | --------------------------------------------- |
| *(none)*, `caster.`, `mob.`, `self.` | the mob                                | until it dies / restart                       |
| `target.`                            | the targeted entity (one per target)   | until it dies / restart                       |
| `skill.`                             | one effect run (a single trigger fire) | that run only, shared with any `run` it calls |
| `global.`                            | the whole server                       | until restart                                 |
| `world.`                             | the mob's world                        | until restart                                 |

Placeholders follow the same rule: `<var.x>` is the mob's, `<target.var.x>`, `<global.var.x>`, `<world.var.x>`, `<skill.var.x>` for the rest. All variables are in-memory and reset on server restart.

## Placeholders

The full set of tokens substituted in text, per recipient:

| Placeholder                                                   | Resolves to                            |
| ------------------------------------------------------------- | -------------------------------------- |
| `<caster.name>`                                               | the mob's name                         |
| `<target.name>`                                               | the recipient/target's name            |
| `<target.uuid>`                                               | the target's UUID                      |
| `<var.NAME>`                                                  | a variable on the mob                  |
| `<caster.var.NAME>`                                           | same, explicit                         |
| `<target.var.NAME>`                                           | a target-scope variable, per recipient |
| `<global.var.NAME>` / `<world.var.NAME>` / `<skill.var.NAME>` | that scope                             |

Because text resolves per recipient, `<target.var.x>` differs for each player a message reaches.

## A hit counter

```yaml theme={null}
counter_boss:
  model: toast
  base: zombie
  effects:
  - var{hits+=1}                          #onHurt @self
  - actionbar{message=&eHits: <var.hits>} #onHurt @target
```

## Long-form mechanics

MythicMobs-style equivalents exist too, useful for the two things `var{}` can't do: math and locations.

| Mechanic                                                             | Aliases                                  | Description                                                                                                                            |
| -------------------------------------------------------------------- | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `variablemath`                                                       | `varmath`                                | Sets `var` to an equation where `value` is its current value and `time` is world ticks. Uses the [formula syntax](particle-equations). |
| `setvariablelocation`                                                | `setvarloc`                              | Stores the target's location in a variable.                                                                                            |
| `variablemove`                                                       | `varmove`                                | Copies `from` to `to`, then unsets `from`. Works across names and scopes.                                                              |
| `setvariable` / `variableadd` / `variablesubtract` / `variableunset` | `setvar`, `varadd`, `varsub`, `varunset` | Long-form versions of `var{...}`.                                                                                                      |

Variables also drive [conditions](flow-control): "enrage when phase is 2" is `if{cond=var.phase >= 2;then=enrage}`.
