User Tools

Site Tools



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

Link to this comparison view

harlowe:else-if [2017/10/09 20:39] (current)
Line 1: Line 1:
 +**(else-if: // [[harlowe:​Boolean|boolean]]//​) -> //​[[harlowe:​Changer|changer]]//​**
 +This macro'​s result changes depending on whether the previous hook in the passage
 +was shown or hidden. If the previous hook was shown, then this [[harlowe:​command|command]] hides the attached
 +hook. Otherwise, it acts like [[harlowe:​if|(if:​)]],​ showing the attached hook if it's true, and hiding it
 +if it's false. If there was no preceding hook before this, then an error message will be printed.
 +=== Example usage: ===
 +Your stomach makes {
 +(if: $size is '​giant'​)[
 +    an intimidating rumble!
 +](else-if: $size is '​big'​)[
 +    a loud growl
 +    a faint gurgle
 +=== Rationale: ===
 +If you use the [[harlowe:​if|(if:​)]] macro, you may find you commonly use it in forked branches of
 +source: places where only one of a set of hooks should be displayed. In order to
 +make this so, you would have to phrase your [[harlowe:​if|(if:​)]] expressions as "if A happened",​
 +"if A didn't happen and B happened",​ "if A and B didn't happen and C happened",​ and so forth,
 +in that order.
 +The (else-if:) and [[harlowe:​else|(else:​)]] macros are convenient variants of [[harlowe:​if|(if:​)]] designed to make this easier: you
 +can merely say "if A happened",​ "else, if B happened",​ "else, if C happened"​ in your code.
 +=== Details: ===
 +Just like the [[harlowe:​if|(if:​)]] macro, (else-if:) only checks its condition once, when the passage or hook contaning
 +it is rendered.
 +The (else-if:) and [[harlowe:​else|(else:​)]] macros do not need to only be paired with [[harlowe:​if|(if:​)]]! You can use (else-if:) and
 +[[harlowe:​else|(else:​)]] in conjunction with [[harlowe:​boolean|boolean]] variables, like so:
 +$married[You hope this warrior will someday find the sort of love you know.]
 +(else-if: not $date)[You hope this warrior isn't doing anything this Sunday (because
 +you've got overtime on Saturday.)]
 +If you attach (else-if:) to a named hook, and the (else-if:) hides the hook, you can reveal the hook later
 +in the passage by using the [[harlowe:​show|(show:​)]] macro to target the hook.
 +=== See also: ===
 +[[harlowe:​if|(if:​)]],​ [[harlowe:​unless|(unless:​)]],​ [[harlowe:​else|(else:​)]],​ [[harlowe:​hidden|(hidden:​)]]
harlowe/else-if.txt · Last modified: 2017/10/09 20:39 (external edit)