# Items and creatures

## Items

An item is anything that can be carried, worn, eaten or used.

**Description** is what the narrator says about it. **Stats and effects** are what it does
when equipped or consumed.

**Interactions** are what happens when a player *uses* it. Simple cases need no code — heal
an amount, apply an effect, be consumed. A healing draught is three clicks.

> **Image: `docs/item-interaction.png`**
> The item editor's Interaction tab with a simple rule configured — a consumable that heals
> and is used up — shown as visual steps rather than code.

When you want an item to do something conditional (*only at night*, *only if the drinker is
poisoned*), that is a [condition](/docs/conditions) and the item editor will take one.

### Variables

A variable is something an item **remembers** between turns. Every variable has a **type**, and
the type decides what it can hold:

| Type | Holds | Use it for |
|------|-------|-----------|
| **number** | a figure | charges, ammo, how many times it has been struck |
| **one of…** | one word from a list you write | `state`: a shrine `dormant` or `powered`, a door `locked` or `open` |
| **text** | any string at all | an inscription, a name someone carved into it, a log a rule appends to |

**one of…** is the common one. Give it the values it may hold, mark which one the item starts
in with the dot, and a rule compares against them by equality — so a value nothing lists is one
no rule can match. That constraint is the point: it is what stops a rule gating on a state the
item can never actually be in.

**text** has no list, and nothing checks what goes in it. That makes it the right choice for
something genuinely open — and the wrong choice for something a rule needs to compare, because
a typo in either place is a comparison that silently never matches.

There is nothing special about the name `state`. It is simply the variable most games want
first. Add `charge`, `mood`, `display`, whatever the object actually tracks, and an item can
carry several at once: a terminal that is both `powered` and showing `menu`.

Variables live on the item's **Rules** tab, next to the rules that read them.

Most items need none. Add one when the same object behaves differently depending on something
that stuck from an earlier turn.

> **Plugin values** on the Description tab are a different thing: numbers a *plugin* asked for
> on every item of that kind — weight, an infection meter. Those belong to the game's systems.
> A variable belongs to this item. See [Fields](/docs/fields).

#### Reading and writing one

A rule reads a variable through `$.item`:

```js
$.item.state === 'LIT'        // the `state` variable
$.item.tags.mood              // any other word variable
$.item.fields.ammo            // any number variable
```

and writes one with a single step, `set_field`, whichever type it is:

```js
$.setField({ field: 'state', to: 'LIT' })          // a word
$.adjustField({ field: 'ammo', by: -1 })           // a number, moved
$.setField({ field: 'ammo', to: 0 })               // a number, pinned
$.setField({ field: 'state', to: 'LIT', onTarget: true })  // on the item this was USED ON
```

There is no separate "set state" step. A state change is a variable write like any other.

### Inputs

An input is what was **done** to an item this turn, and it is never stored. A terminal answers
`help`, `run`, `status`, `exit`; a lever takes `pull` and `push`.

This is a second axis from variables, not a replacement — a terminal can be `powered` (a stored
variable) and receive `run` (an input) in the same moment. Each rule can claim one input with **Require input**,
so one item carries a different behaviour per verb.

Leave it empty for anything a player simply uses.

### Equip requirements

A minimum stat the wearer must have before the item can be equipped at all — a greatsword that
wants 14 strength. The item stays wearable-in-principle and simply refuses anyone under the bar,
rather than being hidden.

Only meaningful alongside an **equip slot**: without a slot the item can never be worn, so the
requirement is never consulted.

## Creatures

Creatures are what fights you. The step only appears when combat is enabled in
[Setup](/docs/editor).

**Stats** decide how dangerous they are. **Loadouts** give them equipment — a bandit with a
sword hits differently from one without.

**Loot tables** decide what drops. Entries carry a chance, so a rare drop is a rare drop
rather than a scripted one.

> **Image: `docs/mob-loot-table.png`**
> A creature's loot table with several entries at different drop chances.

## Effects

An **effect** is a status that lands on someone and wears off: poisoned, blessed, burning.
Effects are their own step because more than one thing applies them — an item, a creature's
attack, a location, a rule.

Give an effect a duration and what it does per turn, and every system that applies it
behaves consistently.

## Abilities

What a character can do beyond a plain attack. Only shown when abilities are enabled in
Setup.

An ability can cost a resource, have a cooldown, and carry a
[condition](/docs/conditions) deciding when it is usable at all.

## Where the numbers come from

Damage, armour and variance are [formulas](/docs/formulas) you can edit — not fixed engine
rules. A game where armour matters more, or where damage swings wildly, changes the formula
rather than inflating every stat.

## Next

- [Quests without code](/docs/quests-no-code)
- [Shops and loadouts](/docs/shops)
