+1 vote
by (130 points)
edited by
I'm working on a story that includes a sort of archive, and want to give the player a way to sort through it. This function is basically like a tagcloud search, and I thought the easiest way to do it would be through the passage tag function.

So after the player answer a few questions , I'd really like to be able to have the program display links only to passages that match the answers. For example, passages can be tagged 'easy\hard' and 'small/large', and after the player decides whether on size and difficulty to look for (setting $size and $difficulty in accordance), he gets a link to all passages tagged with both $size and $difficulty, and only those. So far I haven't even figured out a way to search all passage tags, so not sure if this could work. Can it? What would be the best alternative way to achieve the same functionality?

1 Answer

0 votes
by (159k points)

Please use the Question Tags to state the name and full version number of the Story Format you are using, as answers can vary based on this information. I will assume you are using the latest version of Harlowe which is v3.0.2

While you can use the (passage:) macro to determine which Passage Tags have been assigned to a specific Passage Name (defaults to the current one) there is however no built-in means to programmatically get a list of Passage Names within your story HTML file, which makes it difficult to loop through those passages looking for a set with a specific Passage Tag.

note: Harlowe has been deliberately designed to restrict an Author's access to it's JavaScript based engine, the story format has limited JavaScript support and doesn't have a documented JavaScript API.

If you were willing to use JavaScript to hack into the story format's engine to access its undocumented features then hypothetically you would need do something like the following:

a. Use the Harlowe 3.x Passages.getTagged(tagName) function to access obtain an Array of 'Passage' Map objects, where each such Map object repesents a Passage that had been assigned the specified Passage Tag.

var passages = Passages.getTagged('name-of-passage-tag');

b. Loop through each of the found passage Map objects and use the Map.get() function to obtain the Name of each of those passages.

var names = {};
if (passages.length > 0) {
	passages.forEach(function (passage) { names.push(passage.get('name'))});
}

 

...