version 1/110101 by Edward Griffiths
Section: Inventory Items
One thing we might like to do in a game is give the player an inventory of items that he can use in different situations. Inventory items offer a bit more flexibility than flags alone, but they need to be declared first.
For example, suppose I want to make a game, and the items I want to add are a sword, a shield, and a flask. This is how I'd declare them:
The sword is an inventory item. The shield is an inventory item. The flask is an inventory item.
"[Name] is an inventory item." tells Inform that you're creating a new inventory item and gives it a name. It's a good idea to have one-word item names to keep things from getting confusing. When you have a lot of items in a game, listing them out individually can be cumbersome. The line above can be shortened to:
The sword, the shield, and the flask are inventory items.
Inventory items can be declared anywhere in your code, but it's easier to keep track of them if you group them near the top.
Once your item is declared, it can be used exactly the same way as a flag. Pages can give or remove an inventory item, and choices can require or be cancelled by items:
A choice called InTheArenaA is for In the Arena. "Attack the monster." It triggers Attack Monster. It requires the sword.
But inventory items have a more subtle use. At any time, the player can type the name of an item he's holding to try and use that item instead of selecting one of the choices offered to him. Most of the time, this will simply tell the player "You can't use that here.", but we can change that by adding a special kind of choice to our page called a use. The choice above could be written as a use like this:
A use called InTheArenaA is for In the Arena. It triggers Attack Monster. It uses the sword.
There's no descriptive text because this option is never explicitly printed for the player; he will have to take the initiative to try and use his sword without prompting from the system. Notice "It uses the sword." instead of "It requires the sword." That means that the player will actually have to type in the sword's name in order to use this option.
One problem with Choose Your Own Adventure style stories is how explicitly the player's options are spelled out for him. Having "hidden" choices available for the player makes the game seem a little less confined.