Twine Variables and You

Today I'm going to write a bit on Twine and what I've learned about its usage of variables.

Variables in Twine are really cool. In my early usage of the program a few years ago, I had a limited understanding of it. All of my passages simply linked back and forth to each other. My games didn't keep track of stats or passages clicked, making the overall story painfully linear. It also made it difficult to create branching paths, as they involved a lot of repetition. It never occurred to me to look into variables, because I wasn't sure how they'd add to the experience of interactive fiction.

But now, with a more planned out project in the cards, I have a better idea of what they can do. Variables are useful in Twine because they allow you to keep track of small things that can flavor the experience, as well as hold stats that can affect aspects of the story over time. I've added both sorts of variables to Infernal Handgun Championship.

First, flavor. When the protagonist of IHC wins her first round, she's allowed to say something on the microphone, or choose not to.

What one of those choices looks like:

As you can see above, choosing this passage sets a variable called $spoke_after_round, and sets it to "1," or "active." This variable will remain active until I set it back to zero, which is fine for one-shot passages, but it's something you have to keep track of, as I'll mention later in this post.

After this variable is set, it gets called on a few passages later, like this:

In the next passage, the variable is called on using an if/endif statement. Essentially, if $spoke_after_round is set to 1, then that section of writing will be revealed to the player. The final result looks like this:

The overall difference is minor at best, that much is true. But it adds impact to the story, making it feel more personal. Plus, who knows? Maybe I'll call on that variable again, and make it have some crazy effect on the story...?

That said, there's a more imperative way in which variables are used for IHC, and that's during "Investigation" phases, where Mars and her partner will work together to gain info on the next opponent. During these phases, Mars and Juvo will perform research, and what they choose to learn will impact what passages Mars will have access to during combat, using variables.

 One other note, I'd like to add that "internal handgun championship" is in fact a pun, heh.

One other note, I'd like to add that "internal handgun championship" is in fact a pun, heh.

Because Mars examined her enemy's physiology here, a variable was activated. Later on during combat, she'll have access to a special passage that she wouldn't have otherwise. This is helpful for her because it might increase her $victory variable more than other passages. $victory is a variable that determines whether Mars wins a round during combat in the IHC. The passages she choices will increase and decrease her $victory score. If it's high enough, she'll win, and move on to the next round. If not, she'll have to restart.

I mentioned being careful about what a variable is set at - this is because of a bug I encountered between matches. If I don't set $victory back to 0 after a match is over, it screws with the way the next match plays out.

One last thing: sometimes, variables work in tandem! They're not relegated to investigation and combat separately. The order in which one chooses passages during the investigation can unlock some variables, leading to new variables that might make combat even easier. So make sure to be thorough when during your research!

I'm excited, because I feel like variables add a bit of flavor to this interactive fiction. You'll get to see the full range of choices you can make in Infernal Handgun Championship, both big and small, when it releases in full!