Switch
Switch lines are a simple way to store yes-no-information in Hypstory: Has the door been opened? Has the clue been found? – Switches can be on or off. That makes them ideal for storing true-or-false information.
The state of a switch can later be checked through a check line, which will manipulate text accordingly.
Since the switch line itself does not produce any visible output the following examples will use the check line to show the effects of switches.
Toggle a switch
Think of switches in Hypstory as if they were light switches: You can toggle them between on and off.
Francesca pushes the light switch.
:SWITCH: lightswitch
:CHECK: lightswitch
"Ah, my beloved pizza shop", she calls out cheerfully.
:LINK: Fast forward|toggle light switch
To use a switch start a new line with a :SWITCH: tag. Next to the tag write any name you want for your switch. There are some rules for naming switches. Rule of thumb is: Keep switch names as simple as possible.
When a Hypstory starts, all switches are off. Consequently, the lightswitch in the example above gets turned on first. When you click on the link you return to the same card. As lightswitch is on from the previous visit, it gets turned off this time.
The check line tests which state lightswitch is in. If it's on, the line after the check line is displayed. If the switch is off, the line is skipped.
For brevity, the switch lines are very close to their check lines in the examples on this page. In your Hypstories they will likely be on different cards.
Workflow tip: A short tag for switch lines is :SW:.
Set a switch to on or off
To toggle a switch means to change its state to the opposite: on becomes off, off becomes on.
However, there may be situations when you want to make sure that a switch will be set to a certain state independently of what it was set to before. For that, you can use a + or a - in front of the switch name.
"Any extras?" Francesca asks while spinning the dough on her finger.
:SWITCH: +salami
:CHECK: salami
"Yes, extra salami please. As always."
:SWITCH: jalapeño
:CHECK: jalapeño
And suddenly you change your mind: "Oh and today I'd like some jalapeños, too."
:LINK: Next day|extras
In this example, there are two switches. When the card loads, salami gets set to on. The check line for salami is always true and the text below gets displayed.
jalapeño on the other hand is a toggle. It alternates between on and off every time its switch line is loaded. Hence, every other time the check line will be false and the line below it will not be displayed.
Workflow tip: Use + and - with your switches whenever toggling is not necessary. This will make your source text easier to understand.
Practice tip: Try changing the + before salami to a -. Now this switch will be turned off no matter what it was set to before. And the text about salami will never be displayed.
Set several switches at once
You can set or toggle more than one switch in the same line. Just separate the switch names with a space.
Finally, it's your turn to order: "I'd like a pizza with everything," you declare.
"Alright. Anything else?" Francesca asks.
:LINK: "Yes, extra olives, please." | another extra | append,sticky
:LINK: "No, thank you." | finish | append,sticky
:CARD: another extra
:SWITCH: extraOlives +FrancescaUnderPressure -moderateEating
"Extra olives on your pizza with everything?"
:LINK: "Yesss." | finish | append,sticky
:CARD: finish
"Okay. Stacking may take a while but I'll see what I can do."
:CHECK: extraOlives
Your mouth waters as you think about the extra olives.
:CHECK: FrancescaUnderPressure
As you peek through the kitchen door you see Francesca getting a ladder.
You can mix all three kinds of switches in one line.
Workflow tip: You can use parentheses to improve legibility. The line above could be written like this and work just the same: :SWITCH: (extraOlives) (+FrancescaUnderPressure) (-moderateEating).
Switch name rules
If possible, you should choose switch names that are simple and state clearly what the switch is for. Besides that, stick to these rules so your switch lines work properly:
- Switch names can consist of any letters, numbers, and the underscore (_).
- Switch names can be of any length, but should contain at least 1 letter.
- Switch names are not case sensitive. LIGHTswitch and lightswitch are the same switch.
Workflow tip: In order to make your source text more readable, you can structure your switch names with capital letters or the underscore: lightSwitch, door_bell.