# Coding a text adventure game

**URL:** <https://boards.straightdope.com/t/coding-a-text-adventure-game/208930>\
**Category:** Factual Questions\
**Created:** [October 22, 2003, 4:33pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930 "2003-10-22T16:33:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eonwe](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/eonwe/32/240_2.png) [@Eonwe](https://boards.straightdope.com/u/Eonwe)\
**Post date:** [October 22, 2003, 4:33pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/1 "2003-10-22T16:33:14Z")

</div>

So, how hard would it be to code a text adventure?

I have minimal programming skills (some very elementary basic from waaaaay back, and one CS class in C a few years ago).

I imagine that on the broad spectrum of programming this might not be too daunting a task.

I’m thinking of making this my free-time project for a while, so I don’t mind a bit of work and learning, I’m just curious as to how _much_ learning it’s going to take to pull this off effectively.

---

<div class="post-metadata">

**Author:** ![Finagle](https://avatars.discourse-cdn.com/v4/letter/f/b19c9b/32.png) [@Finagle](https://boards.straightdope.com/u/Finagle)\
**Post date:** [October 22, 2003, 4:44pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/2 "2003-10-22T16:44:35Z")

</div>

It would be very easy – there are lots of authoring systems out there to help you build one. Here’s a good place to start: [http://www-2.cs.cmu.edu/afs/cs.cmu.edu/user/wsr/Web/IF/homepage.html](http://www-2.cs.cmu.edu/afs/cs.cmu.edu/user/wsr/Web/IF/homepage.html)

---

<div class="post-metadata">

**Author:** ![Sofis](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@Sofis](https://boards.straightdope.com/u/Sofis)\
**Post date:** [October 22, 2003, 4:56pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/3 "2003-10-22T16:56:25Z")

</div>

If you want to do it all by yourself, though, then it seems to me that it’s mainly a question of how difficult you want to make it. Writing an intelligent parser that can understand the difference between the verb ring and the noun ring is probably somewhat difficult. Writing a parser that functions like an old LucasArts adventure game, with a set amount of verbs that can be applied to one noun (or possibly two) at a time is probably much less challenging. Writing NPCs that move from location to location and go about their own agendas in a seemingly intelligent manner is more difficult than writing NPCs that stay in one place and only respond to the actions of the player. And so on.

---

<div class="post-metadata">

**Author:** ![Iteki](https://avatars.discourse-cdn.com/v4/letter/i/eada6e/32.png) [@Iteki](https://boards.straightdope.com/u/Iteki)\
**Post date:** [October 22, 2003, 5:00pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/4 "2003-10-22T17:00:26Z")

</div>

Never got around to getting started in TADS, but it seems to be one of the most widely used authoring systems. In the developer FAQ listed in the link above you can read some more about Glk which may be of interest to you as a C coder.

---

<div class="post-metadata">

**Author:** ![MC\_Master\_of\_Ceremonies](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@MC\_Master\_of\_Ceremonies](https://boards.straightdope.com/u/MC_Master_of_Ceremonies)\
**Post date:** [October 22, 2003, 5:07pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/5 "2003-10-22T17:07:36Z")

</div>

Very easy. I wrote one in Sinclair BASIC when I was about 8 or 9 needless to say it was shite, but it is probably the most easy form of game to make esp. using a basic programming language.

---

<div class="post-metadata">

**Author:** ![William\_Ashbless](https://avatars.discourse-cdn.com/v4/letter/w/a87d85/32.png) [@William\_Ashbless](https://boards.straightdope.com/u/William_Ashbless)\
**Post date:** [October 22, 2003, 7:55pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/6 "2003-10-22T19:55:45Z")

</div>

I used to have enormous amounts of fun doing this. I’ve done it in a couple forms of BASIC, Pascal, and C. They’re just plain fun.

One I did on an Apple IIe in its BASIC, and I eventually hit an upper memory limit cause I had so much text description for all of the rooms and objects. The actual space used up by the game logic and various bits of state information (which room you’re in, what objects you’re holding) and the ‘map’ were miniscule in comparison. Fortunately I managed to trim the text back enough to submit it for my grade 10 project.

Granted, I love this stuff (programming) and now do it for a living, so you’ll have to take my opinion with a grain of salt, but it’s not that hard to do.

There are really good ways to do it, and really bad ways to do it, though, to allow you to easily add more ‘things’ and ‘places’ and improve the game’s ‘intelligence’. As an example, you shouldn’t write it so that different parts of your program represent being in different rooms or things.

You should try to write it so that what room you’re in or what things you’re holding are simply ‘state’ information or ‘variables’ containing that information. This enables your program to be more flexible, but at the same time simpler.

```auto

repeat
   get user sentence
   understand player sentence
   apply player sentence to 'update' the player state and world
end repeat

```

This way, the ‘update’ operations as a result of player action can either be very general (move from room to room, pick up or drop an object) or very specific (throw the machine switch).

Depending on what language you choose, you probably want to understand structures or their equivalent. You almost certainly want to learn about arrays. Because of the sentences and processing them, you probably want to learn how to work with strings as well.

As always, KISS (Keep It Simple, Silly). Even a game that just allows \< verb \> \< noun \> can work pretty well.

Starting place: Choose the language you’ll use.

---

<div class="post-metadata">

**Author:** ![Cervaise](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cervaise/32/16693_2.png) [@Cervaise](https://boards.straightdope.com/u/Cervaise)\
**Post date:** [October 22, 2003, 7:55pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/7 "2003-10-22T19:55:47Z")

</div>

Second the recommendation for TADS. It’s a pretty straightforward object-oriented language, and easy to work with. That is, if you’re making an easy adventure. It can be as complicated as you want to make it.

The other advantage is that it’s a popular language, so you can get lots of source code for other games to see how they’re done.

One disadvantage is that, in making it easy for you, it cuts off some flexibility. I once toyed with an adventure on a boat, and I tried to replace the compass directions — north, south, east, west — with nautical directions — fore, aft, starboard, port. I beat my head against it for days before I gave up. Maybe there’s a way to make it work, but I couldn’t figure it out.

But for what most people use it for, TADS is great.

---

<div class="post-metadata">

**Author:** ![tanstaafl](https://avatars.discourse-cdn.com/v4/letter/t/ba8739/32.png) [@tanstaafl](https://boards.straightdope.com/u/tanstaafl)\
**Post date:** [October 23, 2003, 4:17pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/8 "2003-10-23T16:17:52Z")

</div>

If you don’t want to go with TADS, there is also [Inform](http://www-inform-fiction.org), which is very close to what was used for the old Infocom games.

---

<div class="post-metadata">

**Author:** ![cmason32](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@cmason32](https://boards.straightdope.com/u/cmason32)\
**Post date:** [October 23, 2003, 4:22pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/9 "2003-10-23T16:22:26Z")

</div>

If you want to see a nice example of a text adventure game (i.e. a MUD), telnet to [mud.lordtrox.com](http://mud.lordtrox.com): 8500

---

<div class="post-metadata">

**Author:** ![NutWrench](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/nutwrench/32/20193_2.png) [@NutWrench](https://boards.straightdope.com/u/NutWrench)\
**Post date:** [October 23, 2003, 6:07pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/10 "2003-10-23T18:07:41Z")

</div>

Activision recently released the old Infocom Zork text games into the public domain. You can play them in Windows using the [WinFrotz interpreter.](http://www.cris.com/~Twist/WinFrotz/) [Here are links](http://www.geocities.com/SiliconValley/Heights/3222/frotz.html#Links) to Frotz, Inform (mentioned earlier) and other game interpreters here. Several programs include source code and game design tips.

---

<div class="post-metadata">

**Author:** ![tanstaafl](https://avatars.discourse-cdn.com/v4/letter/t/ba8739/32.png) [@tanstaafl](https://boards.straightdope.com/u/tanstaafl)\
**Post date:** [October 23, 2003, 8:37pm UTC](https://boards.straightdope.com/t/coding-a-text-adventure-game/208930/11 "2003-10-23T20:37:07Z")

</div>

If you want a good overview of the systems available for writing adventure/interactive fiction games, check out [Cloak of Darkness](http://www.firthworks.com/roger/cloak/) which gives an overview of about a dozen systems along with a small sample game written in each system.
