Last updated: 10 Mar 18 16:47:15 (UTC)

Creating an index of passages - Twine

[Sugarcube 2] List of all passages with tag

ijohnstonijohnston

October 2015 in Help! with 2.0

Hey I’m wondering if its possible to create a passage that dynamically links to every passage with a certain tag. Like an index page that will update as I add passages

Comments

   [![greyelf](:/43d9210da219fd8506ba4a915c2abc25)](https://twinery.org/forum/profile/greyelf)[greyelf](https://twinery.org/forum/profile/greyelf)

October 2015

The Story.lookup function will return an array of all the passages that meet a set condition, the example shows using it to look for all passages with the “forest” tag.

If you combine that list with a <> macro you should be able to create what you want.

note: I am not current at a machine with SugarCube 2 installed, so the following has not been tested.

<<set $list to Story.lookup(“tags”, “forest”)>> <<for $i to 0; $i lt $list.length; $i++>> <<set $title to list[list[list[i].title>> [[$title]] <>

   [![ijohnston](:/43d9210da219fd8506ba4a915c2abc25)](https://twinery.org/forum/profile/ijohnston)[ijohnston](https://twinery.org/forum/profile/ijohnston)

October 2015 edited October 2015

Thanks! That seems to work great for populating the list but I’m seeing an issue with linking to actual passages. It autocreates a passage called $title and isn’t interpreting the variable in the passage. I just get a number of broken links that all display $title

However if I do <<print $title>> it does correctly show the variable value, lthough not as a link of course

EDIT It looks like it works if i use $title and publish to a file. It seems the error is coming from Twine’s test browser.

   [![greyelf](:/43d9210da219fd8506ba4a915c2abc25)](https://twinery.org/forum/profile/greyelf)[greyelf](https://twinery.org/forum/profile/greyelf)

October 2015 edited October 2015

Currently Twine 2 features like Auto Passage Creation and Broken Link Detection and Passage Map Connections only understands basic markup links like the following:

[[Target Passage Name]] [[Link Text|Target Passage Name]] [[Link Text->Target Passage Name]] [[Target Passage Name<-Link Text]]

So when you use advanced markup links (like ones containing $variables) or macro based links strange things happen like incorrectly named auto-created passages. Generally you can delete these passages.

I did say my example was untested smile

   [(L)](https://twinery.org/forum/profile/TheMadExile)[TheMadExile](https://twinery.org/forum/profile/TheMadExile)

October 2015

As a workaround, you could do something like the following: <<set $list to Story.lookup(“tags”, “forest”)>>
<<for $i to 0; $i lt list.length; ++list.length;++list.length; ++i>> <<print “[” + “[” + list[list[list[i].title + “]” + “]”>> <>
<<unset $list, $i>>

Or, for a JavaScript-style solution, this: <<print Story .lookup(“tags”, “forest”) .map(function (passage) { return “[” + “[” + passage.title + “]” + “]”; }) .join(“\n”)

Both of which should bypass Twine 2’s less than ideal link handling.

Sign In or Register to comment.