0 votes
by (370 points)

I'm trying to use (print:) to display the items in my inventory to show the sellable items, but I want to find a way to omit anything in the array that is an equipped item. Is there a way to add a condition to the printed list, perhaps something like:

(print: $inventory.join(, ) except $quippeditem)

Thanks in advance.

1 Answer

+1 vote
by (159k points)

note: You didn't supply examples of what the values of your $inventory and equipped item related story variables look like, so I will assume they looks something like the following.

(set: $inventory to (a: "Dagger", "Club", "Ring Mail", "Chest Plate", "Leggings"))
(set: $equippeditems to (a: "Dagger", "Chest Plate"))


Harlowe includes a (for:) macro which can be used to loop through the items contained within an Array, you could combine that with an (unless:) macro to check if the current item is contained within the equipped item related story variable.

(for: each _item, ...$inventory)[{
	(unless: $equippeditems contains _item)[
		<!-- code to output the item. -->
	]
}]


If you really want to do everything in one line of code then you could use the (find:) macro to generate a new Array of unequipped items, and then use the JavaScript <array>.join() function to concatenate the new array's elements together.

(print: (find: _item where not ($equippeditems contains _item), ...$inventory).join(', '))

warning: Harlowe isn't designed to play well with JavaScript so you may recieve error messages when trying to do so.

...