a. I'm unsure why you are using a (datamap:) object to store your inventory in because in your example the key and value are the same for each key/value pair, I believe that a (dataset:) object would be better suited to what your example is currently doing.
b. Due to how each (click:) (and related) macro needs to wait until after the whole of passage has been rendered before it can scan the whole of the generated HTML structure to find it's target(s), and due to how certain post modifications to the current page's structure can cause that scanning to be repeated, it is generally a good idea to only use the (click:) (or related) macro whenever you can't achieve the result you're looking for with a (link:) (or related) macro.
c. You should change any short term variables in a Harlowe 2 project to temporary variables whenever possible, that way they don't pad your story History or Saves with unnecessary data.
d. The correct way to hide any visual output generated by a startup tagged passage is to include the following CSS within your story's Story Stylesheet area:
e. It is generally a good idea to give meaningful names to your named hooks, as it helps to make them both unique and easier to remember what they are being used for.
f. The Array documentation of both Harlowe 1.x and 2.x states that you should use parentheses when using an expression (like the contents of a variable) to indicate which collection element you want to reference, this syntax is also true for Datamaps and Datasets.
(set: $map to (datamap: "first", 1, "second", 2))
(set: $key to "first")
Correct syntax to use to access collection element via a value in a variable.
first: (print: $map's ($key))
Invalid syntax that the story format is currently allowing.
first: (print: $map's $key)
The following prototype either modifies the content of one of your existing Passage or it adds new Passages to replace the functionality of some of your own, I used new Passages so that you could keep your existing ones to compare the new code to the old. If you wish you can move the code from my new Passages into your existing ones.
It also adds a new variable named $selected, replaces some existing story variables with temporary variables, and totally ignores some of your existing variables which you could delete if you wish.
1. Initialising the $selected variable in your startup tagged Passage.
(set: $selected to (dataset:))
2. Modifying your Inventory Passage to show the selected items and inventory lists.
It uses two meaningful named hooks to display the list of currently selected items and the inventory list.
Click on two clues to try to link them.
|selected>[(display: "List Selected")]
|inventory>[(display: "List Inventory")]
(link: "Return to game.")[(go-to: $returnTo)]
3. New List Selected Passage, it replaces your current Selecting Items Passage.
It uses a (for:) macro to loop through and displays the current content (if there is any) of the $selected collection.
(if: $selected's length > 0)[\
(for: each _item, ...$selected)[\
(link: "Combine")[(display: "Combine Selected")]
Click a third item to reset.
4. New List Inventory Passage, it replaces your current Inventory List Passage.
It loops through the names of the items in your inventory and uses a (print:) macro to dynamically create a link to allow the selection of each item. It needs to dynamically create the link because the _item temporary variable will not be available at the time the link is selected.
(set: _names to (datanames: $inv))\
(if: _names's length > 0)[\
(for: each _item, ...(datanames: $inv))[\
(print: '(link: _item)[(set: _selectedItem to "' + _item + '")(display: "Select Item")]')
5. New Select Item Passage, it replaces your current Item Selector Passage.
It either tries to a the selected item to the $selected collection or resets the collection, it doesn't need to test if the selected item is already in the collections because a (dataset:) object won't allow the same value to be added more than once. The code includes HTML comments that you can remove if you wish, although the main one does remind you which temporary variables you need to use.
This code block expects the _selectedItem temporary variable to content the ID of the selected item.
(if: $selected's length < 2)[
<!-- Try to add the item to the unique collection. -->
(set: $selected to it + (dataset: _selectedItem))
] (else:) [
<!-- reset the collection. -->
(set: $selected to (dataset:))
<!-- Refresh the page. -->
(replace: ?selected)[(display: "List Selected")]
(replace: ?inventory)[(display: "List Inventory")]
6. New Combine Selected Passage, it replaces your current Evaluation Passage.
It checks if the $selected collection contains particular combinations of items, and does what is needed based on the outcomes.
(if: $selected contains "Cheese" and $selected contains "Pie")[
(goto: "Cheese Pie")
] (elseif: $selected contains "Cheese" and $selected contains "Cake")[
] (else:) [\
Don't be ridiculous, that's not a thing!\
I was going to debug your existing code so that I could explain exactly why it wasn't working in Harlowe 2.x but it was easier and less time consuming just to fix it instead.