# Give items and branch on whether the player has them

> Add and remove items such as keys and letters, change the text or choices depending on whether the player has them, and show the items screen

Items such as keys and letters are set up in `liminalia.json`, and added and removed with the "Add item" and "Remove item" parts. The expression `item("name")` reads how many the player has, so you can use it in conditions and in choice conditions. Items are kept in saves, and come back as they were after load and going back.

The examples on this page use the English sample story, "Waiting for Stars" (choose "A sample story" and English in New Project, or run `lim new --lang en`; the characters are Akari and Sou).

## Set up the items

Items are written as `items` in `liminalia.json` in the project folder. Inside `items`, write the name shown, a picture and a description for each name used from the script.

```json
"items": {
  "observatory_key": { "name": "Observatory key", "image": "items/key.png", "description": "An old brass key Sou left in your care." },
  "lens_cap": { "name": "Lens cap", "description": "The cap of the telescope's lens." }
}
```

| Item | Contents |
|---|---|
| `name` | The name shown on screen (required) |
| `image` | The picture shown on the items screen (a path from the "Images" folder of the assets; optional) |
| `description` | The description shown on the items screen (optional) |

Once `items` is written, "Items" appears in the game's menu. A name in "Add item," "Remove item" or `item("…")` that isn't in `items` is an error in Check.

## Give an item

1. Select the line just before where the player gets the item.
2. Type "item" in the search box at the top of the parts panel, and double-click "Add item" in the results.
3. In the panel on the right, enter the item's name (`observatory_key` here) in `item`. To give more than one, enter the number in `count`.

In the game, when the story reaches that line, "Got Observatory key" appears at the top of the screen. To not show this notification, uncheck `notify`. It doesn't show while skipping.

## Remove an item

With the "Remove item" part, enter the name in `item`. Enter a number in `count` to remove that many; leave it empty to remove all of them.

## Branch on whether the player has it

`item("observatory_key")` returns how many the player has now (0 if none).

- To change the text, write `@if item("observatory_key") > 0` with the "Condition" part.
- To show a choice only sometimes, add `if=(item("observatory_key") > 0)` to the end of the choice line. To show it locked instead, use `locked=(item("observatory_key") == 0)` ([Show or lock choices with conditions](/en/howto/choice-condition/)).

## Show the items screen

The items screen lists the items the player has, in the order written in `items`, and shows the picture and description of the one clicked. Items the player has two or more of show the count (×2 and so on).

- Players can open it from "Items" in the game's menu.
- To put it in the quick menu, check "Items" under "Quick menu" in the game settings ([Set up the quick menu and system buttons](/en/howto/quick-menu/)).
- To open it from the script, set `screen` of the "Open screen" part to "items" (`@open-screen items`). The story doesn't go on until it's closed.

## Let the player choose an item to use

To let the player choose what to use, for example at a door, use the "Pick item" part. The items screen opens with the heading "Use what?", and the name of the item the player picks with "Use" goes into a variable. If the player closes the screen without choosing, an empty string goes in.

1. Find "Pick item" with the search and add it, then enter the variable that receives the name (`temp.used` here) in `variable`. To change the heading, enter it in `title`.
2. Below it, add "Condition" and branch the text on the variable's value.

## In code

```
@item-add observatory_key
Sou "I'll leave this key with you. Will you come back next year to polish the lens?"
@choice
- Open the observatory door -> #door if=(item("observatory_key") > 0)
- Go down the slope -> #home
@end

# door
The door has an old lock on it.
@item-select temp.used title="Use what on the door?"
@if temp.used == "observatory_key"
The key turns, and the door opens with a soft click.
@item-remove observatory_key
@elif temp.used == ""
Maybe not right now.
@else
That won't open the door.
@end
```

For details, see [@item-add](/en/reference/item-add/), [@item-select](/en/reference/item-select/) and [Items and investigation](/en/docs/design/format/#持ち物と探索items) in the documentation.
