So, how do you all handle inventories in Twine? I can imagine using (history: ) and just sending the user to passages when they take an item. But then you can't easily remove/re-add items. Do you use the (dataset: ) array? Can you append or concatenate dataset arrays?
Comments
Datasets might be more efficient (and, yes, you can append to them, etc.), but I always found variables easier to track.
If you need actual code examples, let us know.
I've used a combination of the dataset and count macros and the contains operator. Did what I needed at the time. Might be something you could use as well.
From @L's Twine 2.0 Harlowe Guide
(dataset:) This macro produces a Javascript Set, which is a more limited form of array that does not have numeric properties - you can only query whether it contains a value using contains or is in. It can be used for simplifying (if:) statements - instead of writing (if: $a is "sword" or $a is "axe" or $a is "dagger") dozens of times, you can write (set: $weapons to (dataset: "sword", "axe", "dagger")) and then simply write (if: $a is in $weapons).
contains: This operator is used to check if a string or some text contains another substring. For instance, "Red" contains "R" evaluates to true. (It can also be used with arrays to check for inclusion: (array: 1,4,5) contains 4 evaluates to true.)
(count:): This macro takes an array and a value, and returns the number of times the value appears within the array. (count: $a, "Egg") returns the number of times the string "Egg" is a value in $a. It's like the contains operator, but it produces a number rather than just true or false.
I found this, I think on glorious trainwreck... but it works great:
If I miscredited it, let me know... but I think I saw it there.
—Sage.
Missed that, above, thanks.
1. Place the following in your story's Story Javascript area: 2. Copy the following In your start passage: 3. Create a new passage titled drop your potion and copy the following into it:
4. Dance around with your hands in the air like you just don't care...