0 votes
by (330 points)
(set: $inv to (a:))

(set: $smartphone to (datamap: "name", "Smartphone", "Description", "An iPear smartphone."))

(link: "Smartphone")[(set: $inv to $inv + (a: $smartphone))]

(link: "Inventory")[(goto: "Inventory")]

So far the inventory passage will read:

"Your inventory contains a object Map."

 

1 Answer

+1 vote
by (68.6k points)

Yes, you can access a datamap which has been added to an array.

Try something like the following:

(set: $inv to (a:))
(set: $smartphone to (dm:
	"name", "Smartphone",
	"description", "An iPear smartphone."
))
(link: "Add smartphone")[(set: $inv to $inv + (a: $smartphone))]

[[Inventory]]

And the following in your Inventory passage:

Your inventory contains:
(for: each _item, ...$inv)[(print: _item's name) - (print: _item's description)
]

 

by (330 points)
Works like a charm! Rather than printing the description is there anyway to apply the (mouseover:) macro so that you can have the description appear as you hover over it instead?
by (159k points)

warning: The code contained within the associated hook of a (mouseover: ) macro only gets executed the first time you move the mouse cursor of the target, after that the mouse-over enchantment is removed from the target.

The following is a replacement for the previous Inventory Passage code, it reveals the related description the first time the mouse cursor is moved over a name.

Your inventory contains:
(for: each _item, ...$inv)[\
(print: _item's name)\
(print: "(mouseover: _item's name)[ - " + _item's description + "]")
]

... . the above uses a (print:) macro to dynamically create each (mouseover:) macro (and associated hook) because the _item temporary won't be available at the time the "mouse over" event occurs.

by (68.6k points)

Maybe?  I can't say for certain, though I think the lifetime of _item would be a problem here.  Perhaps someone more fluent with Harlowe would know.

[Edit] There we are.  greyelf to the rescue.  I wasn't aware the Stupid Print Trick™ worked in Harlowe.

...