Store Value
Store value lines let you save numbers and pieces of text for later use: How much money does a character have? How many times has a card been visited? What's the name of a character's favorite pizza?
Stored values can be queried through a check line or printed directly into your Hypstory. Since the store value line itself does not produce any visible output, the following examples will use these two methods to illustrate how you can work with it.
Store a single value
Think of storing values in Hypstory like putting things in boxes and labelling them. Whenever you need something, you get the box with the label for that particular thing.
In order to create such a box you start a new line with the :STORE: tag.
"I have this new bonus system," Francesca explains excitedly. "It's this little coupon. Everytime you buy a pizza, you get a little stamp on it."
She hands you the coupon.
"Ten stamps gets you a free pizza. And since you are my best customer, I've already stamped it. As a thank you gift."
:STORE: $numberOfStamps = 3
(You now have $numberOfStamps stamps on your coupon.)
In order to store a number or some text, you make up a label and write it after the :STORE: tag on a new line. Later on, this label will act as a placeholder for the value you stored.
There are some simple rules for label names. The most important rule is: Every label must have a dollar sign $ as its first character.
After the label you put an equal sign = followed by the number or text you want to store.
If you write a word with a dollar sign $ as first character somewhere in your text, Hypstory will print the value stored under that label into your text. Learn more about how to output stored values.
Workflow tip: A short tag for store value lines is :ST:.
Store several values at once
You can store more than one value in the same store value line. Just put each statement in parentheses.
:STORE: ($aglio = 2) ($tuna = 3) ($specialS = 5) ($fourSalami = 7) ($salami = $specialS + $fourSalami)
"Want to know how many pizzas you had last month?" Francesca asks smirking.
"Yeah, sure."
"That's $aglio Aglio, $tuna Tuna, and a whopping $salami with some sort of salami."
"Mhhh, salami..."
Change a stored value
Storing information can be quite useful in interactive texts. Even more potential lies in changing previously stored information depending on readers' choices.
Overwrite
You can easily store a different value under a label you have already used.
:STORE: $favoritePizza = Pizza Aglio
"When I was little, my favorite pizza used to be the $favoritePizza," you explain.
"I wonder what it might be nowadays," Francesca asks.
:LINK: Piccante | today's taste | append | 1
:STORE: $favoritePizza = Pizza Piccante
:LINK: Salami | today's taste | append | 1
:STORE: $favoritePizza = Pizza Salami
:CARD: today's taste
"It's the $favoritePizza now, because that's the first pie you made for me."
"Seems like someone is trying to gain a free $favoritePizza through flattery," she winks.
In this example, the text Pizza Aglio is stored under the label $favoritePizza. When that label is used inside the following paragraph, the stored text gets displayed.
Then, depending on the link the readers click a different text is stored under the same label. The new text replaces what was stored before. Consequently, when the $favoritePizza label appears in the paragraph afterwards the new text gets displayed.
Practice tip: If you're not sure how lines 5 through 8 work, the article about link overflow is the place to go.
Modify
Hypstory can also change a previously stored value instead of overwriting it. For that, you can use simple arithmetic: +, -, *, /.
:STORE: $numberOfStamps = 5
You have $numberOfStamps coupon stamps. Today's plan: :LINK: Buy some more pizza and get stamps.
:CARD: Buy some more pizza and get stamps
:STORE: $numberOfStamps + 1
"Your pizza is coming right up," Francesca stamps your coupon. "You have $numberOfStamps stamps on your coupon already."
:CHECK: $numberOfStamps < 10
:LINK: Buy some more pizza and get stamps
:CHECK: $numberOfStamps == 10
:LINK: Get free pizza
:CARD: Get free pizza
"Look, you have ten stamps already! That's a free pizza for you today."
In this example, $numberOfStamps starts at 5. When you buy a pizza at Francesca's you get a stamp for it. The number of stamps increases by 1 and you can navigate to the same card again.
When your stamps add up to 10, a different link is displayed. It leads you to the card where you get a free pizza.
In order to add 1 to a stored number, just write the label of that number, then a plus sign + and then the number 1. You can also add other numbers. And you can use other mathematical operators, such as - for subtraction, * for multiplication, / for division, and the parentheses ( ).
:STORE: $numberOfStamps + 1 is a simplified version of :STORE: $numberOfStamps = $numberOfStamps + 1. Despite their different appearance they work just the same.
Practice tip: Read up on check lines to understand the full potential of values in Hypstory.
Store a value based on another value
Whenever you store a new value or modify/overwrite an existing one, you can include other values that have been stored previously.
:STORE: $myStamps = 5
:STORE: $newStamps = 3
"Hey Francesca, my friend started a diet and gave me their coupon."
"Okay, let me put your friend's stamps on your coupon real quick."
With a few swift moves Francesca adds $newStamps stamps to the $myStamps stamps you already had. Plus one, because she likes you.
:STORE: $myStamps = $myStamps + $newStamps + 1
"Here you go. You have $myStamps stamps now."
This example starts with two stored values, $myStamps and $newStamps. Both values are printed into the text. $myStamps is 5.
Then, the sum of these values plus one (5 + 3 + 1) gets stored under the label $myStamps. When $myStamps is printed into the text after that, it's 9.
Like before, there's a simpler way to write the last :STORE: line: :STORE: $myStamps + $newStamps + 1. When you use this short notation with more than one label, Hypstory will use the first label to store the new value, in this case $myStamps.
If you switch the labels and write :STORE: $newStamps + $myStamps + 1 instead, you will get the same sum (9). But that sum will be stored under the label $newStamps.
Label name rules
If possible, you should choose label names that are simple and state clearly what the stored value is for. Besides that, stick to these rules so your store value lines work properly:
- Label names must start with a dollar sign ($).
- Label names can consist of any letters, numbers, and the underscore (_).
- Label names can be of any length, but should contain at least 1 letter. They cannot contain any spaces.
- Label names are not case sensitive. $COUPONstamps and $couponstamps are the same label.
Workflow tip: In order to make your source text more readable, you can structure your label names with capital letters or the underscore: couponStamps, favorite_pizza.
Some label names are already taken, i.e. reserved for values that are built into Hypstory. You'll find everything about them in the generate value article. Storing values under these label names will not work.