Hi All,
I’m using Twine 2.3.5 with Harlowe 3.1.0. First time asking a question here, so sorry in advance for any mistakes in the post.
I’m trying to set up a passage where players can add crafting ingredients to a recipe, before clicking “proceed” to craft it.
This was fully successful and appeared the way I wanted it to with the manually written code below:
(set:$list to (dm:))
(set:$ITEMquantities to (a:1,2,3,4,5))
|=
{
|ITEM1hide)[ ]
(if:$list contains "ITEM1")[
(replace:?ITEM1hide)[
(Link-repeat:"Remove ")[
(Set:_Remove to "ITEM1")
(move:$list's (_Remove) into _buffer)
(replace:?plan)[$list]
(replace:?ITEM1hide)[ ]
]
]
]
ITEM1:(dropdown:bind$ITEM1amt,...$ITEMquantities)
(Link-repeat:"Add")[
(Set:$list to it + (dm:"ITEM1",$ITEM1amt))
(replace:?plan)[$list]
(replace:?ITEM1hide)[
(Link-repeat:"Remove ")[
(Set:_Remove to "ITEM1")
(move:$list's (_Remove) into _buffer)
(replace:?plan)[$list]
(replace:?ITEM1hide)[ ]
]]
]}
=|
**Crafting plan:**
|plan>[$list]
|==|
[[Proceed]]
Where I would manually replace ITEM1 with the respective item name (i.e. wood, metal, etc…) and copy/paste the new code. This worked so that only once any amount of an item was added, the “remove” link would appear (which is the issue I’m having below).
In an effort to quickly make different passages like this with different lists, I tried using a (for:) loop with and array containing the item names, like so:
(set:$list to (dm:))
(set: $items to (a:"wood","rock","metal"))
(set:$ITEMquantities to (a:'1','2','3','4','5'))
|=
(for: each _item,...$items)[
{(Link-repeat:"Remove ")[
(Set:_Remove to _item)
(move:$list's (_Remove) into _buffer)
(replace:?plan)[$list]
]
_item:(dropdown:bind _itemamt,...$ITEMquantities)
(Link-repeat:"Add")[
(Set:$list to it + (dm:_item,_itemamt))
(replace:?plan)[$list]
]}
]
=|
**Crafting plan:**
|plan>[$list]
|==|
[[proceed]]
This works fine, but only because I removed the reference to the hide-able hook at the beginning, meaning that the “remove” link is ever present (the whole thing fully functional, just not the look I’m going for).
What I would like is something like:
(set:$list to (dm:))
(set: $items to (a:"wood","rock","metal"))
(set:$ITEMquantities to (a:'1','2','3','4','5'))
|=
(for: each _item,...$items)[
{
|_itemhide)[ ]
(if:$list contains _item)[
(replace:?_itemhide)[
(Link-repeat:"Remove ")[
(Set:_Remove to _item)
(move:$list's (_Remove) into _buffer)
(replace:?plan)[$list]
(replace:?_itemhide)[ ]
]
]
]
_item:(dropdown:bind$_itemamt,...$ITEMquantities)
(Link-repeat:"Add")[
(Set:$list to it + (dm:_item,$_itemamt))
(replace:?plan)[$list]
(replace:?_itemhide)[
(Link-repeat:"Remove ")[
(Set:_Remove to _item)
(move:$list's (_Remove) into _buffer)
(replace:?plan)[$list]
(replace:?_itemhide)[ ]
]]
]}
]
=|
**Crafting plan:**
|plan>[$list]
|==|
[[proceed]]
I realize that |_itemhide) by itself isn’t the way to go, I’ve tried using the (hook: _item) macro to generate a new hook in each loop iteration, but it didn’t work, even when I added a unique string to the end in each loop using a string of (i +1). Basically it replaces all the “hide” hooks at once with the same code, so you can only remove the most recent item added (with any of the “remove” links generated). I think there may also be issue is with how I’m referencing it in the (replace:) macro.
Any help on how to generate these hook names and properly reference them with the replace command would be greatly appreciated. I can use a python script to rapidly generate the code from a list, but this only helps if the items and amounts are set before the story starts, not if the $items array is going to be updated mid story.
Thanks!