This is an old revision of the document!
The «if» macro can be used in formats like these:
<<if expression>> Text <<endif>>
<<if expression>> Text <<else>> Text <<endif>>
<<if expression>> Text <<else if expression>> Text … <<endif>>
condition is an expression that can evaluate to true or false. Text is any amount of passage text that you wish to display only if the condition is true. «endif» is a macro tag indicating the end of the «if» macro invocation.
Consider a passage like this:
You return to Selator's hut. A merry fire is crackling in the kitchen, and something is cooking that smells delicious. He greets you warmly and asks, “Have you got the berry?” If you have got the purple berry of the Antherica plant, turn to 175. If not, turn to 52.
(Steve Jackson and Ian Livingstone, Scorpion Swamp)
It would be nice if the story could track whether the protagonist found the berry or not, and branch accordingly. We can do this by simply noting the name of the passage where the berry was found:
:: Antherica You have no doubt, from Selator's description, that you have found the Antherica plant. Half your mission is completed. Now you must return to the village with the precious berry.
Then we can use the «if» macro and the visited() function to display a passage indicating victory:
You return to Selator's hut. A merry fire is crackling in the kitchen, and something is cooking that smells delicious. He greets you warmly and asks, "Have you got the berry?" <<if visited("Antherica")>> "Wonderful!" he exclaims... <<endif>>
You should take care when writing «if» macros that you write correct expressions, and that you remember what the “and” and “or” keywords are capable of.
<<if $health > 2 and < 4>>
This is invalid because the
< operators (and indeed, all such operators) require a distinct value to be on both sides of it. In a sense, it is internally interpreted as
«if ($health > 2) and ( < 4)», which is obviously nonsensical. So, you must rewrite this as
«if $health > 2 and $health < 4».
<<if $name is "Perone" or "Pavone">>
This is also invalid, for a different reason: it will be interpreted as
«if ($name is “Perone”) or (“Pavone”)» - which is to say, it is true if $name is “Perone”, or if the string “Pavone” is not false. This, of course, means that it's always true - an undesirable outcome. You must rewrite it as
«if $name is “Perone” or $name is “Pavone”».
When a passage containing an «if» macro is displayed, the «if» and «endif» macro tags are removed from the text. But, the line on which the tags was placed will remain - thus, if it was by itself on a line, it will create a blank line. You can choose to fix this by ending the tags' lines with a backslash:
You leap over the sawblade with deft ease. <<if $alive>>\ She laughs. "Still not dead? How callous of you to scorn Death's loving embrace!" <<endif>>\
You may, for larger «if» constructions, use the «nobr» macro instead:
You glare at the alien control panel. <<nobr>> <<if $red>> The red button blinks <<if $earplugs>> and hisses<<endif>> at you. <<endif>> <<endnobr>>
«else» is a macro that is used to indicate text that should be displayed if the condition is false.
The door to the left leads to the pantry. <<if visited("Pantry")>> No way are you going back in there! <<else>> Sounds like a good place to search... <<endif>>
The «else» macro can itself contain another “if condition”, which causes the contents to only display if THAT condition is true:
<<if $health is 3>>\ You're in tip-top condition - fighting fit and frankly fearsome. No human or god can lick you! <<else if $health is 2>>\ DOOMED! You're DOOMED, puny player!! You've lost already! YOU CANNOT WIN!! MWAHAHAHAHA! <<endif>>\
You can insert as many «else if»'s as you want inside an «if» / «endif» pair.
(Note: if you prefer, you can also write “else if” as “elseif”.) else if