Coding Exercise: Creating a Text-Based Game

As a writer, I’m most curious to use code to build interactive stories.

Photo Courtesy of Pixel-Shot

I’ve always been curious about how technology can elevate literature in new, unique ways. I took part in a digital humanities internship when I was an undergrad at Stockton University, which was my first glimpse into the future of what it might mean to be a writer. I learned basic markup languages, HTML and CSS, and about how to apply my writing skills to social media marketing.

I want to explore what storytelling is going to look like in the coming decades. Paper books and ebooks are cool, but I’m fascinated by interactive storytelling. I’ve written a few short stories in Twine, which is a simple text-based platform for telling interactive, nonlinear stories.

Interactive fiction isn’t completely new, but it is largely underappreciated.

Image Courtesy of GameSkinny

I want to create a more text-heavy game for the sake of preserving the literary narrative. The above game, Spider And Web, was written and created by Andrew Plotkin back in 1997 and 1998. The idea of text-based games is held in the gaming community as something old-fashioned, but it’s something that has never truly thrived as a way to consume fiction in the literature community. That’s something that I want to change.

Interactive storytelling changes the very nature of writing and gives the opportunity to pull the reader in far more deeply. Readers aren’t just passive consumers in content—they become engaged players. By giving the reader choices, they become more involved in the story, and the writer can make a profound emotional impact.

I want to build a simple choice-driven text-based game in p5.js.

One of my biggest motivations for learning to code is finding ways for it to support my writing. I’ve built things in Twine before, but Twine doesn’t require coding. I want to challenge myself by really learning how choice mechanics work in the backend and building a very simple choice-driven game myself in the p5.js editor.

Image Courtesy of BytesIn

Though I’m learning to understand programming functions, I’m still rather fuzzy on how much variability and flexibility certain programming functions and objects afford.

For this first attempt, I want to keep the user interface very simple. I plan to have a forward arrow to advance through the story and simple buttons for players to choose their responses.

I put together some very simplistic pseudocode, but this is definitely something I need to flesh out more.

I want to experiment with if statements and the p5.clickable library.

I feel like the most direct way to create a branching storyline would be with if and or statements. This should be able to help the player advance through the story seamlessly.

Image Courtesy of Github

However, I do think this could get very lengthy and might not be the most efficient way to code this idea.

I want to experiment with the p5.clickable library to see if this has some mechanics that I could harness to make this idea easier. Having a little extra interface help would definitely make it easier to make the button mechanics more visually pleasing.

For this project, the story must shine.

Photo Courtesy of VioletKaipa

I envision the story as having four or five different points where the player needs to make a choice to advance the story. I want to have three different potential outcomes that come about depending on the player’s choices.

So far, I’ve had some trouble going into a coding project when I have a very specific idea of what I want to accomplish. I usually end up discovering that I don’t have quite enough coding knowledge to execute my vision and have to make modifications. It’s definitely going to take some extra research on my end to figure out how to make if/then statements support the choice mechanics I have in mind.

I want to explore interactive storytelling and this will be my first small step in that direction. I feel like this is knowledge that will benefit me in the long-run. Even if I end up using software like Twine or advanced 3D software like Unreal Engine for interactive storytelling in the future, I feel like the backend mechanics of what it takes to build a choice-driven story in code is valuable to understand.

Writer and poet from Neptune. Instructional designer in NYC. Grad student at @NYUTandon studying Integrated Digital Media.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store