0 votes
by (180 points)

Hello everyone!

I'm using Twine 2.1.1 and Harlowe 2.1.0.

I used this awesome tutorial to build an inventory system and it works great so far. However, I came to a bit of a halt with what I'm trying to do.

Say, a character walks into a room and they have an option to inspect multiple locations (desk, floor, wardrobe, etc.). They can pick up things from these locations and some things they can ignore. Meaning, there can be different inventory combinations on different game options and outcomes. As in, they can have a pen, a book in their possession in one outcome, or a pen and a pair of boots in the other.

I feel that if I proceed with the story this way, I'd have to copy and build the same set up for later scenes over and over, depending on what is in the inventory. I presume there could be a better way about this? My brain can't quite wrap around it right now :D

Could anyone please advice? I'll provide necessary code, not sure what exactly I can provide right now apart from my inventory example:

(set: $inv to $inv + (ds: "leatherbound book")) 

 

2 Answers

0 votes
by (180 points)
I was thinking about this a moment, can I possibly determine the player's inventory via if? As in, the game will check if they have this, this or that item and determine if they can do this or that action? Trying to build a picture in my mind :D
by (560 points)
I'm not completely sure what your issue is. Can you provide more details? And yes, you'd most likely be using if-statements to manipulate your inventory system.
by (44.7k points)

Section 5 on the page you linked to explains how to have different things happen based on what is or isn't in your inventory.

0 votes
by (159k points)

Supplying either a link to the Inventory system article (or video) you are using or a code example showing how it is implemented would help anyone answering your question know which of the multitude of such systems you are using.

I will assume it behaves something like the following:

<!-- Initialise the Inventory system. -->
(set: $inv to (a:))

<!-- Add an initial item to the inventory. -->
(set: $inv to it + (a: "book"))

<!-- The Reader chooses to pick up an item. -->
(link: "Pick up pen")[
	(set: $inv to it + (a: "pen"))
]


You can use the Harlow Array data type's contains operator to check if one or more things are currently in the inventory Array.

(if: $inv contains "book" and $inv contains "pen")[You write a note in the book.]

 

by (44.7k points)

They already did supply a link.  Where it says, "I used this awesome tutorial", the "this" is a link to it.

by (159k points)
ty, even knowing it's there I still have problems noticing it.
...