Inventory screens are a staple of video games of all genres - especially in RPGs and interactive fiction. Even in the earliest IF games, like Zork, typing "inventory" will tell you what your character has in their possession. Here is a quick tutorial for how to program an inventory page in your own Twine interactive fiction game.
Behind the scenes:
Make a list of all your variables corresponding to objects you can pick up. Personally, I like using CamelCase like this: $HasRing or $HasKnowledgeOfGhost. For the most part, since your character will either have an item or not, it's ok to make these variables Boolean (only stores the values true or false).
Coding in Twine:
1. In the intro passage, you will set all your variables to false. The code should look like this
(set: $HasLamp to false)
2. For the passage where the character picks up an item, change the variable to true. The code:
(set:$HasLamp to true)
3. Make a new passage which will serve as the inventory screen. This should be accessible from most pages of your game, if you want your player to be able to check their inventory, so make sure to add [[Inventory]] to each passage.
The inventory page itself is a list of Boolean if commands that check the state of the variable. If it is true, a description will be shown. If false, nothing appears. The code:
(if:$HasLamp is true)[A lamp, glowing with a warm heat.]
Video walkthrough:
Play a game I wrote with an inventory page, "You Feel Like You've Read This In a Book": https://ifdb.org/viewgame?id=j10f35m2va268msd
In this game, your inventory is split up into physical items and knowledge. I coded knowledge in the same way.
Happy writing!
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.