01 logo

Let's Create: Text-Based Game Part 1

First week of creating a new text-based game.

By Dwayne ChapmanPublished 11 months ago 8 min read
2

I dabble in a lot of different types of projects, but one thing I enjoy is game creation because it employs both story telling as well as logical thinking in creating interactive gaming mechanics to play with.

For this journey, I am going to be using Twine to create an interactive fiction text-based game and steadily adding in new gaming elements each week to hopefully have something I can present that is playable by the time fall rolls around.

Anyway, throughout this journey I'm going to explain thought processes as well as show the systems I use to create the gameplay mechanics available in the game, which will hopefully give you, the reader (future player?), an appreciation into how much thought and work goes into creating various gameplay elements that we use everytime we play.

Day 1 - Stat Variables & Events

Starting with just a free hour here, I'm going to just focus on some simple adventuring stats that can be manipulated in the future but will give our playing character essential variables to keep track of throughout the game.

Right now all I am going to create are: Health and Stamina variables and create a temporary "work" and "bed" events that replenish them to the full. The "work" event shouldn't be available if the Stamina variable is at 0. The player should be able to see their health and stamina values.

Using the mark-up language known as Harlowe in Twine first we set the variables at the start of the passage.

Creates two variables "charHealth" and "charStamina" and sets their values to 10.

While we use the starting passage to set up the games initial variables, we also need a way to begin the game and start off in our first room. We'll call it bedroom and link to it.

Using the link macro with the double []'s, we can create some text which when clicked links us to another passage.

Inside the Bedroom passage, we'll display the player's health and stamina at the top before greeting the player giving them two buttons to click to take them to two other passages of "Work" and "Sleep".

For the work button, we'll create an if statement to check the player's current stamina. If it's less than 1, then they will get the message that they are too tired to work and will only have the go to bed option available to them. Otherwise, they can work and drain stamina.

Using Boolean "If" and "Else" statements we can see if the player has enough stamina to work.

If the player decides to work, we need to decrease their stamina by one point. We'll do that inside the "Work" passage and immediately send them back to the "Bedroom" passage so they can see their new current stamina.

Set stamina to its current value - 1. Then immediatly go back to Bedroom passage.

Once the player's stamina is drained, only the Go to Bed option will be available for them, inside the "Sleep" passage we'll reset health and stamina back to 10. After which we'll immediatley boot them back into the "Bedroom" passage once again.

Sets Health and Stamina to 10 again and boots player back into the bedroom passage.

With that done, my free hour for Day 1 comes to an end and we have a basic set-up to test the current variables in the game. So let's have a quick look at what the player would see of the current game build.

If stamina is > 0, then player can work or go to bed.

If stamina is < 1, then the player can only go to bed.

Days 2 & 3 - $$$, Shop, Stat Increase, & Basic Inventory

With a small amount of work done so far, let's make today a little more productive by adding three basic mechanics to the game. A money variable, a shop location, and an inventory to track what you have and make use of some potions. These potions will set the max health and stamina to increase.

Starting off with creating a variable to teack our money, we'll just call is charMoney like we did with health and stamina. Initializing it in the Start passage the same way, then displaying it in the Bedroom passage also the same way. Then let's go to the Work passage and increase money by $1.

Adds $1 to the variable for money.

Now wait a minute. Using $ calls upon a variable and we want to show a $ sign for money to display it in the Bedroom passage. So we'll have to use a verbatim macro so that the game displayed the $ sign. For this we'll use '$' to signify we want the game to ignore all macro used between the two (') symbols.

Using verbatim macro to display a $ sign to the player before calling the money variable to display.

Now with that out of the way, let's create two more passages, one for Inventory and one for Shop and link to both of them from the Bedroom passage.

We need two more variables to track health and stamina potions, so I'll add those now as potionHealth and potionStamina and set them to 0 like we did with money in the Start passage. Next we'll link to the Inventory and Shop passages from the bedroom passage.

Linking bedroom to inventory & shop

We still have a few more variables and passages to add in to make it all work.

First we'll deal with the two new variables, maxHealth and maxStamina setting both of them to 10 in the Start passage. Then we'll tweak the sleep mechanic to = maxHealth/maxStamina instead of resetting them to 10 so that they can change as the max stat changes.

When sleeping, change health/stamina = max health/stamina variable.

We need this to deal with the potions affecting the character's stats, so let's go to one of two new passages and call it "UseHealth". In this passage is should work similar to the Sleep passage and the player should not see it as it changes the in-game variables.

The passages should look something like this as we use up a potion.

Adding 1 to max health and taking 1 potion away.

Doing the same with the UseStamina passage, we'll now add a use button in the Inventory passage if potions > 0.

Display potion #, if statement checks if > 0, if true add "Use" command.

With a working inventory system, we can now go to the shop and use similar tactics in buying and adding potions. In the two new BuyHealth/BuyStamina passages, we'll just chainge the potionHealth variable to add one instead of taking one away.

Adding 1 health potion then returning to shop.

Using almost the exact same logic for checking if we have potions, we'll see if the player can afford a potion to buy instead of use.

The Buy command only appears if the player has sufficient money.

Days 4 & 5 - An Enemy Appears

Great, we have a way to restore stats, make money, buy potions, and increase stats, now let's add an enemy into the game. First creating a passage called Fight and adding a link to it from the Bedroom. Using the same logic we used in potions, we'll check to see if the player has any current health to actually fight with before giving them the option to enter the Fight.

Simple check on health > 0 before giving option to go fight.

We'll add another passage Arena so we can set the enemy's stats to reset outside of actually fighting anytime the player enters the Fight passage.

Sets up the enemy health and offers them the chance to fight.

In the Arena we'll create one passage, Attack which will split off into 2 other passages Win or EnemyAttack, and EnemyAttack will again split off into 2 passages Lose or Arena to start the next round of attacks.

Arena passage displaying health and Attack command.

When you click attack, it should hurt the enemy and checks to see if the enemy is defeated, if so, you win, if not, enemy attacks. Same with the enemy's attack.

Deals damage, checks if you won, if not enemy attacks.

Enemy deals damage, checks if you lost, if not goes back to arena to show stats.

Win and lose screens simply let the player go back to the bedroom after informing them if they won or lost.

Day 6 - Test Run

Not a whole lot of time for today's coding, so going to do a quick test run to make sure everything works fine.

Stats were fine, enemy fight seems to be bug free (for now), but found a problem in the shop. We forgot something!

While we gave the player a potion if they had > $4, we didn't take away the money, so effectively $5 allows the player to collect infinite potions. This is common in programming, the programmer either forgets about something or the player does something the programmer didn't think of and this creates a "bug" that needs to be patched in. So we'll quickly patch this.

Simple line of code to take away character's money when buying a potion.

Day 7 - A Stunning Performance

Today we'll be right back into the fighting mechanics by adding a new ability that takes away from Stamina, stuns the opponent for a few turns and allows the player to potentially turn a losing fight into a winnable one.

We'll start by making the enemy's health 12 and making the stun duration for 3 turns counting the turn the player hits him for. We'll also make it cost 5 stamina per stun attack.

First, we'll make a passage named Stun and link to it from Arena alongside Attack.

If player has 5 or more stamina, offer them the chance to use stun attack.

To make full use of this effect, we'll add another variable to the Fight passage and call it enemyStun and set it to 0. Then in the Stun passage we'll make enemyStun = 3 and take away 5 stamina from the player. You cannot add onto enemy stuns, so re-stunning an enemy at 2 or 1 will only reset it to 3 turns again.

Stuns enemy for 3 turns, takes away player stamina.

Now we have to deal with the enemy's turn. First by checking if they are stunned, and then either taking 1 stun turn away or letting the enemy attack the player if they are not stunned.

Checks enemy's stun status.

Quick Playtest - End of Week

We've been hammering away at adding new features in the game, next week we'll focus a few days on tuning up passages and variables to make future content not feel too cluttered and make some programming lines easier.

A quick test of the code we have thus far, ignoring the potions we lose if we straight up attack the enemy, while we can win if we use both of our stun attacks to get in some free hits.

Thanks for joining me on the first week of this. I'm aiming for weekly updates on progress and sharing each step of the way with you all so that you too can create a text-based game using the Twine engine and Harlowe code.

Using the coding logic I have shown you so far, you can easily create a mini-game series identical to many start-ups and solo developed games out there. Whether it be a choose-your-own adventure novel or a lite-adventure game. Throughout the summer we'll try to add in more gaming elements to allow us to create even more complex games.

how to
2

About the Creator

Dwayne Chapman

I write stories and articles of all genres. If my content is to your liking, stay tuned! I have more coming and will be creating a community discord channel for those who want to follow me and get updates on future projects.

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2024 Creatd, Inc. All Rights Reserved.