I'm using Twine 2, SugarCube 2.
I'm considering adding an inventory tab to
my game.
But I'm not sure how to implement it, and whether it would work well with this type of game.
If I were to do it I'd want something simple, perhaps even just a faded gray link that's always there (except on title and end passages) and says something like "inventory" or "your pocket," and when you click on it you see a list of what you're currently carrying, and if you're not carrying anything, it says something like "inventory is empty". And you should always be able to go from the inventory passage/tab back to the passage you just came from.
How can I do that? I think I read somewhere about Inventory macros but I can't find that now.
Comments
If you want something simple, then you probably don't need the various inventory macros. A simple key item type inventory is easily done with story variables.
You checked out the game, so maybe you remember that it already has a key item type inventory system, but the player can't see what they're carrying. So I want every passage to have a link that says "inventory", and when you click on it, you're taken to a separate inventory passage.
The inventory passage would have a list of everything you're carrying right now, and a "back" arrow that would take you back to the passage you clicked from.
So if you just found a key, the inventory passage would say "A key". And if you just used the key and aren't carrying anything else, it would say "Empty." And so on.
I don't know where you'd want to place the inventory link, however, I think at the top isn't a bad place for it in your current layout—say, top right. With that in mind: create a new passage, name it PassageHeader, and place the something like following within: Do not put extra line breaks in there.
Create a new passage, name it Inventory, and place something like the following within: NOTES
ADDITIONAL TIPS
While looking at your project to be able to give you an on-target example for the inventory screen/page, I noticed some subpar coding behaviors. Here are some suggestions that will, hopefully, be of use to you.
And thanks for the boolean clarification. I didn't know the "is true/false" part is unnecessary. I'll make changes accordingly (in the meantime, is it actually harmful to have the overly complicated conditionals, or is it just inconvenient?).
To have the player access it, you can put a link in StoryMenu, or StoryFooter that leads to a passage containing your inventory. In order to get back you can just use a link with previous().
For displaying the Inventory, you can go about it however you want but I simply run the $Inventory array through a 'for' loop which prints out the values until there are no more.
Every time you want to add something to the inventory you can insert the new item name or variable into $Inventory using .push(). So if I'm adding $book to $Inventory I'd use.
If you want to have inventory items be links you can do that as well but it needs some modification. Hopefully this is somewhat helpful!