Can you access a datamap within an array like so:

0 votes
asked Dec 30, 2017 by silamander (340 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
answered Dec 30, 2017 by TheMadExile (32,880 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)
]

 

commented Dec 30, 2017 by silamander (340 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?
commented Dec 30, 2017 by greyelf (58,490 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.

commented Dec 30, 2017 by TheMadExile (32,880 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.

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...