ChapelR / custom-macros-for-sugarcube-2

A collection of systems and macros for Twine.
https://macros.twinelab.net/
The Unlicense
166 stars 44 forks source link

Feature Request: Additional Simple Inventory Containers Macro #3

Closed AccreditedDesign closed 7 years ago

AccreditedDesign commented 7 years ago

Hi Chapel, So I'm working with the containers system and wish to call the names and/or count the number of specific items in a certain separate passage's inventory. Here's the situation: I have a passage ::Old Wooden Chest which is set as a container and where drops can be made. In the story, you're to collect TREASURES which are always in all caps, and drop them there in the chest as you discover them in the story. I have a simple script set up in that passage to detect when all are possible are dropped and if so goto an end screen: <<if psgInv.all('TREASURE1', 'TREASURE2', 'TREASURE3', 'TREASURE4')>>\ <<goto "End">> <</if>>\ I have a separate StoryMenu passage, ::Stats which list various things. Among them, I'd like to have a "Treasures Found" and for it to list a number like 5/20 and list the names of the treasures possibly. In looking at the available macros and functions, I was eyeing: <<setcontainer (optional: passage)>>, psgInv.all, and psgInv.any As far as I can tell, there's no current way without modifying the JavaScript to do what I describe, but perhaps I've missed something in the documentation? Let's say the player has found and then dropped TREASURE1, TREASURE2 and TREASURE3 into the chest passage, but has not yet found TREASURE4. I'm looking for a way to code something like: Query passage "Old Wooden Chest" for "TREASURE1", "TREASURE2", "TREASURE3", "TREASURE4" The variable would then compare the request against what's actually there, and then spit back the number present, in this case 3, and also possibly the names of the items which were found there. In my Stats menu, I'd list it something like: Treasures Found: 3/4 You have found TREASURE1, TREASURE2, TREASURE3 If this is too far out there I understand, LOL. Perhaps there exists a way to already do it with the available macros but it escapes me. Thanks again.

ChapelR commented 7 years ago

If I understand you correctly, you need to access a specific passage inventory. You can do that via the story variable created by the system, which is $containers by default.

For example: <<if $containers['Old Wooden Chest'].includesAll('list', 'of', 'items')>>... <</if>>

There's also a function used internally by the macros to return a passage's inventory, since the story variable could be changed: <<set _psgInv to setup.simpleInv.containers.getItems('Old Wooden Chest')>> would pass the array of items present in the passage in the temporary variable _psgInv as a reference (i.e. changes to this temp variable will alter the passage's inventory array, so be careful).

I'm not sure if that's exactly what you're asking for, though. I should probably add some of this to the documentation.

AccreditedDesign commented 7 years ago

Awesome, that was what I needed Chapel. Thank you again.