User Tools

Site Tools


displaying_a_passage_within_another

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
displaying_a_passage_within_another [2013/12/13 01:59]
l [Shorthand form]
displaying_a_passage_within_another [2017/10/10 00:39] (current)
Line 1: Line 1:
-===== Displaying a Passage Within Another ===== +#​redirect ​display
- +
-Sometimes you'd like two diverging branches of a story to merge back into one. You can already do this with a well-placed link, but you can make the transition seamless with the ''<<​display>>''​ macro. Consider this source code, which paraphrases one of the first scenes of //The Hitchhiker'​s Guide to the Galaxy:// +
- +
-<​code>​ +
-:: The world is ending +
-The world is about to end -- something about construction of a bypass? -- and +
-you only have time to buy one thing at the pub. +
-* [[Buy another beer]] +
-* [[Buy a sandwich]] +
- +
-:: Buy another beer +
-Ford had said something about muscle relaxant. +
-You decide to take him at his word. +
- +
-<<​display '​Vogons begin'>>​ +
- +
-:: Buy a sandwich +
-For some odd reason you've been craving a cheese sandwich all day, and it looks +
-like you won't have a chance to have one anytime soon. +
- +
-<<​display '​Vogons begin'>>​ +
- +
-:: Vogons begin +
-You hear a great rumbling from outside, and rush outside to see what's going on... +
-<<set $vogons to true>>​ +
-</​code>​ +
- +
-In both of those passages, the text of the passage "​Vogons begin" will be displayed after the text. Since its text contains the macro <<set $vogons to true>>,​ then it will indeed be set in both of those passages. +
- +
-====A note about tags==== +
- +
-What the <<​display>>​ macro actually does is copy the text from the given passage into the current passage. It doesn'​t actually display the passage in its own right. What this means is that, if a passage has CSS styling specific to it, then that styling will not be applied to the current passage! +
- +
-====Using a variable to display a passage==== +
- +
-The <<​display>>​ macro treats its argument as a [[about expressions|code expression]]. This means that you can put a passage name in a variable and then display it: +
- +
-<​code>​ +
-With a rush of wind, you arrive in the <<​print $destination>>​! +
-<<​display $destination>>​ +
-</​code>​ +
- +
-If, say, $destination contained the string "​Cellar",​ and a Cellar passage existed, it would print "With a rush of wind, you arrive in the Cellar!"​ and display the cellar passage. +
- +
-====Shorthand form==== +
- +
-The <<​display>>​ macro is special among Twine macros because it has a shorthand form. Instead of writing <<​display "​passage">>,​ you can simply write <<​passage>>,​ as if it was another macro. (**Note:** this only works when the passage name is a constant value that does //not// contain spaces!) This allows you to write Twine stories in a "​template"​ style: +
- +
-<​code>​ +
-:: Battle start +
-With a resounding cry of "<<​battlecry>>",​ your <<​minions>>​ rush into battle! +
- +
-:: battlecry [nobr] +
-<<if $morale > 2>> +
-Victory is ours! +
-<<​else>>​ +
-Help us! +
-<<​endif>>​ +
- +
-:: minions [nobr] +
-<<if $species is "​globbo">>​ +
-globlings +
-<<​else if $species is "​varavar">>​ +
-vara-thralls +
-<<​endif>>​ +
-</​code>​ +
- +
-As you can see, the "​battlecry"​ and "​minions"​ passages can be displayed in place of those <<​[[if]]>>​ statements throughout the story, with little hindrance to the readability of the passage text. +
- +
-====Avoid the <<​display>>​ loop==== +
-**It is possible to lock up a reader'​s Web browser by using the ''<<​display>>''​ macro improperly,​** like this: +
- +
-<​code>​ +
-:: Oops +
-<<​display "​Oops">>​ +
-</​code>​ +
- +
-When displayed, the passage will keep attempting to display itself over and over until the reader force quits his Web browser. This doesn'​t do permanent damage, but it will not endear yourself to your reader.+
displaying_a_passage_within_another.txt · Last modified: 2017/10/10 00:39 (external edit)