DAY 13: CODE FOR THE FUTURE
Part one of last night’s challenge in our process of creating a great interactive fiction gamebook was setting up the code to lock in the introduction. Today I wanted to dig deeper and showcase the code that I came up with. Today I have two goals, show exactly how I coded the introduction breaking down each line and then set some daily goals for the rest of the week.
NOTE: Posting code on this blog is difficult so I will post the files but for easy reading, I will put ** to substitute << & >>. See the attached files for actual code.
I wrote out a bit of story starting in the action but remaining suspenseful. The first passage reads:
The cold wind blows onto your skin tickling you back to reality.
You've been a DJ for 15 years now, but this is the first time you've fallen asleep at the turn tables.
You reach over and tap the large triangle to stop an EDM rendition of a Christmas Carol you can't fully make out.
However, as soon as the large hall filled with reindeer and elves go silent you can hear your spouse...
This is followed by the buttons:
**button [[Mrs. Claus|femalepreference]]****/button**
**button [[Mr. Claus|malepreference]]****/button**
When writing a Twine game I like to start the story at a tense moment, but also I suggest using the first few passages to creatively ask the user for the basic information like gender and preference. I ask the gamebook players to give preference of spouse so that I can write love interests accurately using widgets. (We will get to widgets later.)
The player of our CYOA story makes a choice here and we know something that needs to be kept for future use, what their preference is for a spouse. Note that I put that as the title of the passages (femalepreference). Now let’s record that choice and ask for gender of player in a slick way…
**nobr****set $claus to "Mr. Claus"****/nobr**
When you hear $claus call your name it turns your blood cold as the wind. That's not a shriek of happiness that $claus is known for. It's a fearful, dreaded, painful shriek.
"What wrong love?" you ask.
"You don't know?" he replies. "I thought you were special, but you are just like all the other..."
**button [[Its out there|iamnnb]]****/button**
The first thing I do in this passage is set the response from the previous passage in a variable. **nobr** (which means no break) makes the words between the two invisible as it pertains to white-space. This is useful to hide code in most Twine games and could be important on certain DF networks so heads up there. Next inside **nobr**&**/nobr**(the second of which closes the command) I set the variable $claus to “Mr. Claus”. So from now on whenever the user reads $claus it will show Mr. Claus unless i set the variable $claus to something new, or the game ends. This is a simple explanation but it is vital to you making an incredible game. If you have questions email me: email@example.com.
Then I get to the story and we see that $claus is surprised that Santa doesn’t have a clue what’s going on. Then I slyly get the user to choose gender which means I needs to assign the variable again based on decisions made.
How would that code look? I’ll leave the code here and will go more into this tomorrow.
GOALS: Our goal moving forward is 1,000 words a day. Even if I only go over a basic concept here, try to follow your outline and lock in 1,000 words. Also note that I keep my passages short and paragraphs short as well. This will translate well across various platforms.
Make great decisions guys!