0 votes
by (550 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
by (2.5k points)
selected by
 
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

 

by (550 points)
Works perfectly! Thanks.
0 votes
by (159k 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);

 

by (8.6k 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);
}

 

by (550 points)
edited by
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!
by (8.6k 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.
by (159k 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.

...