SugarCube 2.0: Story and Passage
While creating in Twine, there might be a need to know details about the story and the passages within it. That's when the <a href="http://www.motoslave.net/sugarcube/2/docs/api-story.html">//Story//</a> API can be very useful.
For example, if we wanted to know the name of the Story, there is {{{Story.title}}} functionality to retrieve that.
<<set $test to Story.title>>
The name of the story is: $test
[[Looking for passages]]
Beyond simply the name of the story, we can also look for and get passages from inside the story by their name through using {{{Story.has()}}} and {{{Story.get()}}}
<<if Story.has("searchTarget")>>
<<set $passageContent to Story.get("searchTarget").processText() >>
The content of "searchTarget" is $passageContent
<</if>>
(Note: The above code is effectively the same thing as using the {{{<<include>>}}} macro.)
[[Passage]]
Some content!Like //Story//, there is also a <a href="http://www.motoslave.net/sugarcube/2/docs/api-passage.html">//Passage// object</a> representing the results of searching for a passage with {{{Story.get()}}}. Like with //Story//, each passage also has its own //title//, //tags//, and unprocessed content, //text//. However, the most common function is {{{Passage.processText()}}}. Used in the last example, it returns the processed text.
<<set $content to Story.get("searchTarget2").processText() >>
The processed content is $content.
<<set $example to "Some content">>
$example