I am working on a rough dungeon-crawler system in Twine with Harlowe 2.1.0.

After battle, you can check for loot. If successful, you find a random weapon, armor, magic item, etc. What I want is to make the found item's name to be clickable and, when clicked, display the object's infromation in a pop-up alert.

I got the link part working just fine. The problem I have is that when I write a command like

(alert:"The (print:$weapon's name) does XYZ")

The text returned in the pop-up is literally "The (print:$weapon's name) does XYZ."

How do I get the variable to display properly in the pop-up alert? Is it even possible? Is there a better command to use?

2 Answers

The (print:) macro injects it's output directly into the HTML structure being generated for the current Passage, and you are trying to use it to inject a value into the String literal you are passing to the (alert:) macro. This combinating won't work.

You can achieve the result you want by using String concatenation to build the value you pass to the (alert:) macro.

I'm not sure if it is possible to use macros and stuff like that in alerts. What you could do is instead of having the weapon's name, use a more general term, like 'sword' or 'bow' or whatever, but the actual link to click will have the weapon's specific name.

In my personal opinion though, those alerts may get annoying for the player, as it slows down the gameplay. I would personally only use popups when I want to use the (prompt:) macro. However, that is just my opinion.

I am drawing the result from a set of arrays, so I am unsure of how I would choose to say which weapon it is in plain text without having some way to connect the result to alert.

Here's the code for the random pull, where $weapons is an array that contains eight (8) different weapons.

(set:$loot to
(either:"Weapon","Weapon","Exotic Weapon","Armor","Armor","Potion","Scroll","Magic Item"))
$loot:
(if:$loot is "Weapon")[(set:_weapon to (random:1,8))You found the (print:$weapons's (_weapon))]

TBH, I am currently building this in conjunction with a pen-and-paper game as a means to keep from having to write a million things down and cut down on pointless dice rolling, so it is more for me than for another person at this point.