0 votes
by (390 points)

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?

Thanks!

2 Answers

0 votes
by (158k points)
edited by
 
Best answer

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.

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

 

by (390 points)
Fantastic. It worked. Thank you!!
0 votes
by (6.2k points)
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.
by (390 points)

Thanks for the feedback.

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.

by (6.2k points)
I'm not too good with arrays, but maybe this page could help if you're struggling with them:

https://twine2.neocities.org/
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.
...