User Tools

Site Tools


harlowe:if

Differences

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

Link to this comparison view

harlowe:if [2017/06/19 00:05]
l
harlowe:if [2017/10/09 20:39]
Line 1: Line 1:
-**(if: // [[harlowe:​Boolean|boolean]]//​) -> //​[[harlowe:​Changer|changer]]//​** 
- 
-This macro accepts only [[harlowe:​boolean|booleans]],​ and produces a [[harlowe:​command|command]] that can be attached to hooks 
-to hide them "​if"​ the value was false. 
- 
-=== Example usage: === 
- 
-''​%%(if:​ $legs is 8)[You'​re a spider!]%%''​ will show the ''​%%You'​re a spider!%%''​ hook if ''​%%$legs%%''​ is ''​%%8%%''​. 
-Otherwise, it is not run. 
- 
-=== Rationale: === 
- 
-In a story with multiple paths or threads, where certain events could occur or not occur, 
-it's common to want to run a slightly modified version of a passage reflecting the current 
-state of the world. The (if:), [[harlowe:​unless|(unless:​)]],​ [[harlowe:​else-if|(else-if:​)]] and [[harlowe:​else|(else:​)]] macros let these modifications be 
-switched on or off depending on variables, comparisons or calculations of your choosing. 
- 
-=== Details: === 
- 
-Note that the (if:) macro only runs once, when the passage or hook containing it is rendered. Any 
-future change to the condition (such as a [[harlowe:​link|(link:​)]] containing a [[harlowe:​set|(set:​)]] that changes a variable) won't 
-cause it to "​re-run",​ and show/hide the hook anew. 
- 
-However, if you attach (if:) to a named hook, and the (if:) hides the hook, you can manually reveal 
-the hook later in the passage (such as, after a [[harlowe:​link|(link:​)]] has been clicked) by using the [[harlowe:​show|(show:​)]] macro 
-to target the hook. Named hooks hidden with (if:) are thus equivalent to hidden named hooks like ''​%%|this)[]%%''​. 
- 
-=== Alternatives:​ === 
- 
-The (if:) and [[harlowe:​hidden|(hidden:​)]] macros are not the only attachment that can hide or show hooks! In fact, 
-a variable that contains a boolean can be used in its place. For example: 
- 
-<​code>​ 
-(set: $isAWizard to $foundWand and $foundHat and $foundBeard) 
- 
-$isAWizard[You wring out your beard with a quick twisting spell.] 
-You step into the ruined library. 
-$isAWizard[The familiar scent of stale parchment comforts you.] 
-</​code>​ 
-By storing a boolean inside ''​%%$isAWizard%%'',​ it can be used repeatedly throughout the story to 
-hide or show hooks as you please. 
- 
-=== See also: === 
- 
-[[harlowe:​unless|(unless:​)]],​ [[harlowe:​else-if|(else-if:​)]],​ [[harlowe:​else|(else:​)]],​ [[harlowe:​hidden|(hidden:​)]] 
- 
-**(unless: // [[harlowe:​Boolean|boolean]]//​) -> //​[[harlowe:​Changer|changer]]//​** 
- 
-This [[Harlowe]] macro is the negated form of [[harlowe:​if|(if:​)]]:​ it accepts only [[harlowe:​boolean|booleans]],​ and returns 
-a [[harlowe:​command|command]] that can be attached hooks to hide them "​if"​ the value was true. 
  
harlowe/if.txt ยท Last modified: 2017/10/09 20:39 (external edit)