How to Create your own Text Adventure

How to Create your own Text Adventure

Unlike most people my age, I didn?t grow up playing video games; I grew up playing text adventures, or interactive fiction.

After exploring the dungeons of Zork, all 12 year old me wanted to do was to learn how to create my own game. Nine years later, I?ve finally accomplished that goal!

Text adventures are a fun, creative way to tell interactive stories, and they?re easier to make than you think!

Step 1: Download Inform

Inform is a programming language made specifically for creating text adventures.

It makes it easy for anyone to create their own, whether you know how to program or not. Unlike other programming languages, it?s mostly made of existing English words and grammar!

Download the correct version of the software onto your computer!

Step 2: Open Inform and create a new project

When you open Inform, you?ll see a welcome screen, like below. Click ?Project? under ?Create New? to start your text adventure. Give it a great name!

Image for postInform Welcome Menu

Step 3: Create a room

The bulk of writing text adventures in Inform relies on three ideas: objects, descriptions, and relationships.

Every room, item, and person that is in your text adventure is defined as an object in the code. You make these objects come to life by providing descriptions of them and having them form relationships through actions.

Inform will give you a little bit of code to start out with, including the definition of your first room. It has defined ?Example Location? as a room using this line of code:

Example Location is a room.

However, ?Example Location? is a really boring name for a room, so instead I?m going to make it my bedroom.

Julianna’s Bedroom is a room.

Step 4: Run your code

You might have guessed this already, but all you need to do to run your code is to press the big button in the top left corner that says go!

Image for postGo button in Inform

After pressing run, your code will compile and run. It should look something like this:

Image for postRunning game

Since Inform was made for creating text adventures, it already has a lot of the classic text adventure commands built in! Check out this site for some ideas of commands to try out.

When you type in a command and press enter, the software will generate a response based on your code.

You, the player, are an object in the game. Since you?re the only thing in the bedroom, all you can successfully do right now is interact with yourself (try ?examine me,? ?kiss me,? and ?rub me? ?).

Step 5: Add a room description

Being by yourself in an empty room isn?t super fun, so the next step is to create your setting. Go back to your code and add a description to your room. This is how the room will be described to the player.

For example, here is how I would define the description of my room:

Julianna’s Bedroom is a room. The description is “The white walls of the room are matched by the color of the furniture. A rack of shoes sits neatly in one corner and the dresser and bedside table are clear of dust.”.

The description can be as brief or long as you like.

If you run your code again, you can see the description of your room!

Image for post

Step 6: Add an object

Now the player can see things in the room, but they still can?t interact with anything!

So, we?re going to add an object that the player can interact with. By default, players can pick up and drop any object that you put into the room.

Since this is my bedroom and I like to read, I?m going to put a book in the middle of my bed. To create an object, you just need to mention what it?s called and what room it?s in. You can also add a blurb about the object that will be included in the room?s description.

So, now my code reads

Julianna’s Bedroom is a room. The description is “The white walls of the room are matched by the color of the furniture. A rack of shoes sits neatly in one corner and the dresser and bedside table are clear of dust.”.A book is in Julianna’s Bedroom. “There is a book lying in the center of the bed.”

Instead of using the name of the specific room, you can also just use ?here? to refer to the most recently defined room.

Try running your code again. Now, you can pick up and drop your object!

Step 7: Add another room

Some text adventures will take place in one room, but most have multiple rooms for players to move through and explore! You can create another room the same way we created the first one ? defining it and adding a description.

Since my first room is a bedroom, I?m going to add a living room. To allow the player to move from one room to another, you have to define how the two rooms are located in relation to one another using cardinal directions.

The Living Room is a room. The description is “This is a small room with a couch in the middle. On one wall there is a bookshelf.”.The Living Room is east of Julianna’s Bedroom.

If I run my code and use the command ?east? while I?m in the bedroom, I will move into the living room and if I use ?west? while I?m in the living room, I?ll move back to the bedroom.

Try it out for yourself!

Step 8: Make a container

Since I have a book and a bookshelf, I want to be able to put my book onto the bookshelf. We can make this happen by creating a bookshelf object that is a container.

A container is a special type of object that you can put other objects into.

We can turn an object into a container using the phrase ?is a container.?

A bookshelf is a container in the Living Room.

This line of code creates a bookshelf object in the living room and allows for things to be put inside of it.

To try it out, run the code and enter ?pick up book? while you?re in the bedroom. Then, move to the living room and use the command ?put book in bookshelf? to put the book on the bookshelf.

Image for post

Step 9: Make an end state

No game is complete without and ending.

To create an ending, we?re going to use a conditional statement to check if the book is in the bookshelf. If it is, we?ll end the game.

We will want to check this condition every turn. This can be done with the following line of code:

Every turn: if the book is in the bookshelf, end the story.

Once you have an end condition, you can run and play the whole game! By default, after the game ends, the player will have the options to restart, restore a saved game, quit, or undo.

Image for post

Step 10: Keep adding on!

This is just the start of what you can accomplish with Inform! You can create a whole text adventure with just the ideas from the steps above or you can dive deeper into what you can do with Inform!

Check out Inform?s book for inspiration and more examples or the Interactive Fiction Database for lots of text adventures that you can play!

Happy adventuring! ?

Complete Code:

“Demo_Project” by Julianna StevensonJulianna’s Bedroom is a room. The description is “The white walls of the room are matched by the color of the furniture. A rack of shoes sits neatly in one corner and the dresser and bedside table are clear of dust.”.A book is in Julianna’s Bedroom. “There is a book lying in the center of the bed.”The Living Room is a room. The description is “This is a small room with a couch in the middle. On one wall there is a bookshelf.”.The Living Room is east of Julianna’s Bedroom.A bookshelf is a container in the Living Room.Every turn: if the book is in the bookshelf, end the story.

16

No Responses

Write a response