Homebrewery’s Variables is a feature that really takes a minute to commit to memory. I’ve long avoided writing about it, mostly because I haven’t found a strong reason to use it. However, it seems like more features are likely to built on top of it going forward. And, because I hardly actually use the Homebrewery for writing content, I wouldn’t be surprised if other authors are using this extensively (or wishing they were). So let’s give it a shot.
Variables allows you to declare a variable in one spot, assign it a value, and emit or manipulate that value later on in your brew.
Assign and Emit
For a first example, imagine you had a story you were fleshing out, but couldn’t commit to a name for your hero. Well, you could write it out, and then later use Find & Replace to change whatever you had. Or, you could use a variable:
Here, the variable hero is declared, and is assigned a value Henry in one line, [hero]:Henry. Note, the value is not emitted immediately, it is consumed and does not appear in the html/preview. In the next line, it is emitted with $[hero]. Now you can change “Henry” up where it is assigned to “Paul” and it’ll flow into the text.
Multi-line
Multi-line values are possible, too, which means you need to be careful to have an empty line between each new variable assignment. Multi-line can mean two things: the output should be multiple lines of text that translate to multiple paragraphs in your brew, or the output is something like a table that is composed of multiple lines in Markdown, but comes out as a single table. If aiming for the former, you want to end each line with \ to indicate a line break. If making a table, you won’t need that slash.
Variables in Variables
You can also emit variables within the assignment of another variable. Say you have a cast of characters centered around our hero Henry, and for some reason you think it’s a good idea to always refer to them by how they relate to the hero:
The above is emitting the original hero variable into subsequent variables, heroMom and heroDad. Do I vouch for this particular variable setup in this example? Probably not, it’d be a tough sell. It’s taking a standard, human-readable markup format (Markdown) and throwing variables in. But this is just a teaching aid– if you are using variables in clever ways, please write about it and share with others (reddit, discord, etc).
Immediate Emit
If you want to assign and emit your variable in one swoop, that is possible with $[hero](Henry):
Math
Math can be done with variables. The common example is determining modifiers in D&D. The modifier below is determined by taking the Charisma (17), subtracting 10, dividing the result by 2, and rounding down. We have set the CHA to 17, do those operations to it, and place it all inside a new “immediate emit” variable called score. Changing the [CHA] assignment up to to another number will automatically update the modifier.
How it Fits
If you are paying attention, you might notice that this syntax models a more familiar and standard Markdown syntax: links and images. Links and images are like variables, in that their declarations are consumed and emit something totally different.