Key Items
Key items are the few things the story needs, such as a key that opens one particular door. They sit in a pocket of their own, so a full bag never blocks one, and they cannot be dropped or sold. A used-up key never comes back, and a check finds doors that can no longer be opened.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Key Items" to my game.
What it should do: Key items keep the story from breaking. The player can never lose, sell or fail to pick up the one thing that lets them go on.
Use these starting values:
- pocketSize: 16 keys
Watch out for these common mistakes:
- A full bag blocks the key: Tell your AI: keep key items in a pocket of their own that the bag limit does not touch.
- The key can be sold or dropped: Tell your AI: refuse to drop, sell or throw away any key item, and say why.
- The same key is picked up twice: Tell your AI: remember every key that was ever taken or used, and ignore a second pickup of the same key.
- A one-use key is needed by two doors: Tell your AI: run the check that lists shut doors whose key is gone. Give each one-use key a single door, or make the key reusable.
- The key is spent by a failed try: Tell your AI: only spend a key after the door has really opened.
- Keys matched by name: Tell your AI: give each key an id that never changes, and match doors to keys by id.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
What it does
Key items keep the story from breaking. The player can never lose, sell or fail to pick up the one thing that lets them go on.
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| pocketSize | 16 keys | How many keys the pocket holds. It is separate from the bag, so a full bag never blocks a key. Set it above the number of keys in the whole game: a key that does not fit is left in the world, and the player may not find it again. |
What usually goes wrong
A full bag blocks the key
The player reaches the key with a full bag, and the game treats the key like any other item. The pickup fails, the key stays on the floor, and the player walks on without knowing they missed it. Later the door cannot be opened.
Fix: Tell your AI: keep key items in a pocket of their own that the bag limit does not touch.
The key can be sold or dropped
The player sells the key, throws it away, or leaves it behind in a chest. The door can never be opened and the story cannot go on.
Fix: Tell your AI: refuse to drop, sell or throw away any key item, and say why.
The same key is picked up twice
A key respawns after reloading, or the player walks back into the room. Now there are two copies. A used-up key even comes back and opens its door a second time.
Fix: Tell your AI: remember every key that was ever taken or used, and ignore a second pickup of the same key.
A one-use key is needed by two doors
A key is used up by the first door it opens, and a second door also needs it. If the player opens the wrong one first, the other can never be opened.
Fix: Tell your AI: run the check that lists shut doors whose key is gone. Give each one-use key a single door, or make the key reusable.
The key is spent by a failed try
The player tries the key on a door it does not fit, or on a door that is already open, and the game still uses it up.
Fix: Tell your AI: only spend a key after the door has really opened.
Keys matched by name
The door checks the key by the name shown on screen. Renaming it, or translating the game, makes every door stay shut.
Fix: Tell your AI: give each key an id that never changes, and match doors to keys by id.
How to check it works
- An empty pocket. you pick up the brass key: the pocket holds the brass key.
- You already hold the brass key. you pick it up again: nothing happens and you still hold exactly one.
- A pocket that holds two keys, and both places are taken. you try to pick up a third: it is refused, the pocket is unchanged, and the key is not marked as taken.
- You hold the vault key. you try the gate, which needs the brass key, and a door that does not exist: both are refused, the gate stays shut, and you keep the vault key.
- You hold the brass key and the gate uses it up. you open the gate: the gate is open, and the brass key is gone from the pocket.
- You hold the vault key and the vault does not use it up. you open the vault: the vault is open and you still hold the vault key.
- You hold the brass key. you try it on the vault, which needs the vault key: the door stays shut and you still hold the brass key.
- You have opened the gate with a one-use key. you try the gate again: nothing happens and the key is not spent twice.
- You hold the brass key. you try to drop, sell or throw it away: it is refused and you keep the key. The same try with an item you do not hold does nothing.
- You used up the brass key on the gate. you pick up the brass key again: nothing happens and the pocket stays empty.
- Two doors need the same one-use brass key. you open the first one, then run the check for doors that cannot open any more: the check names the second door. If the key can be used again, the check names nothing.
- A game with a gate, a vault and a cellar. you try a door called constructor: it is refused as a door that does not exist.
Works well with
- Inventory System: If keys share the bag limit, a full bag can make the story impossible to finish. Keep the key pocket next to the bag, not inside it, and check the pocket first when an item is picked up.
- Storage Chest: A key put into its own chest can never be taken out again. Unlock the chest with the key from the pocket, and never let the chest store the key.
- Shop (Buy and Sell): A key sold for coins would shut a door for good. The shop does not list key items, so the sell step refuses them as an item it does not trade.
Common questions
how do i stop the player from losing a quest item
Keep quest items in a pocket of their own, and refuse to drop, sell or throw them away. A key that cannot be lost cannot leave the story stuck.
what do i tell my ai to add keys and locked doors
Paste this: Add key items in their own pocket, separate from the bag. Each door names the id of the key it needs. Keys cannot be dropped or sold, a key is picked up only once, and a key is used up only when the door really opens. Add a check that lists shut doors whose key is gone.
should a key disappear after it opens a door
Only if no other door needs it. A reusable key is the safe default. If a key is used up, remember that it was, so it cannot be picked up again, and run the check for doors that can no longer open.
what is a soft lock in a game
It is a place where the player cannot go on and cannot go back, and nothing tells them. A shut door whose key is gone is the most common one, so check for it before the game ships.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 15 tests pass on the reference code.
Your AI gets the code
Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it