[Snowman] Getting the tags of any passage

0 votes
asked May 16 by Menti (390 points)

Is there a way of obtaining the tags of a passage that is not the current, having the name of that passage?

Thanks!

2 Answers

0 votes
answered May 17 by klembot (2,380 points)
selected May 17 by Menti
 
Best answer

In fact Snowman does parse passage tags. Try this:

story.passage('passage name you are interested in').tags

This is an array. If you'd like the tags of the current passage, use:

story.passage(story.history[story.history.length - 1]).tags

 

commented May 17 by Menti (390 points)
Works perfectly! Thanks.
0 votes
answered May 17 by greyelf (97,410 points)

Snowman doesn't process the tags of a Passage (current or others) so you will need to use JavaScript to look at the Passage's tw-passagedata element, which is a child of the tw-storydata element that stores the definitions of all the passages.

The following example shows how to use jQuery to first obtain the relevant tw-passagedata element based on the Passage's name, and then how to use the attr() function to obtain the String value that contains the assigned tag names (each separated by space character).

var passage = $('tw-storydata tw-passagedata[name="Name-of-Passage"]');
var tags = passage.attr('tags');
console.log('tags: ' + tags);

 

commented May 17 by Akjosch (7,310 points)

I'd encapsulate it a bit:

window.getPassageTags = function(pass) {
	var passage = $('tw-storydata tw-passagedata[name="' + pass + '"]');
	return (passage.attr("tags") || "").trim().split(/\s+/).filter(_.identity);
}

 

commented May 17 by Menti (390 points)
edited May 17 by Menti
Amazing! Thank you so much. This allows a major feature in the game I'm writing.

One more question about this. I use twee2, not Twine. If one has a passage title like this:

:: Title [tag]

What is the passage name? Does it include the space before the tags? Thanks!
commented May 17 by Akjosch (7,310 points)
I can't say anything about twee2, but TweeGo strips the (outer) spaces and I can't imagine twee2 doing it differently - they are needed for links, after all.
commented May 17 by greyelf (97,410 points)

What is the passage name? Does it include the space before the tags?

In TWEE Notation the passage name of your example would be Title without the start or end space characters.

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.
...