> ## 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.

# 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, and in any number, 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.

Because text resolves per recipient, `<target.var.x>` differs for each player a message reaches. Every other placeholder (`<caster.hp>`, `<target.l.x>`, `<random.1to5>`, …) is on [Placeholders](https://entities.lodemc.net/placeholders.md).

## 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' variable mechanics work as written, and cover the two things `var{}` can't do: maths and locations.

| Mechanic | Aliases | What it does |
| - | - | - |
| `variableSet` | `setvariable`, `setvar` | Sets a variable. `scope=` picks where it lives. |
| `variableAdd` / `variableSubtract` | `varadd`, `varsub` | Adds to or subtracts from a number. |
| `variableMath` | `varmath` | Sets a variable to an equation, where `x` is its current value. |
| `variableSetLocation` | `setvariablelocation`, `setvarloc` | Stores a location in a variable; read it back with `@variableLocation{var=…}`. |
| `variableMove` | `varmove` | Copies `from` to `to`, then unsets `from`. Works across names and scopes. |
| `variableUnset` | `varunset` | Removes a variable. |

Variables drive [conditions](https://entities.lodemc.net/conditions.md) too: "enrage when phase is 2" is `if{cond=var.phase >= 2;then=enrage}`, or `variableEquals{var=caster.phase;value=2}` in a `conditions:` list.


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