Posted on by & filed under game development, learning.

I often speak and write about text-based gaming. The topic is relevant to the publishing audience that I usually address, but I do it mostly because I love the genre. I’ve enjoyed playing text games since I was young, but they were also instrumental in teaching me to program.

At Safari we think a lot about effective ways to learn technology. What worked for me was simply having a program I wanted to write, one that felt achievable given my complete ignorance of the subject. When I was a kid, writing a “real” video game seemed impossible: it required math skills I didn’t have, and the use of very low-level programming languages like assembly that I didn’t think I could learn. Writing a text game is completely achievable in any language, including very simple ones like BASIC. In doing so I learned many of the fundamentals of programming: taking user input, storing data in variables, and simple control structures like loops and — I’ll admit it — GOTO.

People still write text games today. The annual interactive fiction contest (in its 19th year!) wrapped up recently. Although interactive fiction games can be narratively and technologically complex, a simple game is easy to write, and it’s still a more engaging introduction to programming than “output 100 numbers in the Fibonacci sequence” or many other Computer Science 101 problems.

And so, text-based games remain a good choice for an introduction to programming, one that is realizable in any number of programming languages.

Note: If you’re interested in writing proper interactive fiction, I recommend using an engine designed for this purpose. Today, the two most popular systems are Twine, which is a browser-based engine using JavaScript and other web technologies, and Inform, which generates traditional interactive fiction games in which a user types commands like “OPEN DOOR.” Although my heart lies with the old-school style, Twine has an active and vibrant user community, and is a great way to get into authoring in this genre.

Lisp, the granddaddy of interactive fiction

I was delighted to find that Land of Lisp by Conrad Barski teaches Lisp by implementing a simple adventure game. This is particularly charming because the earliest and most famous text games were written using a Lisp-like language (the original manual for ZIL is available as a PDF).

In Land of Lisp, the reader is taught how to write the game in Common Lisp rather than any domain-specific language:

and is taken all the way through writing a simple English parser to an actual playable game:

Screen Shot 2013-11-24 at 4.16.10 PM

This is exceedingly cool, not only as a gentle introduction to Lisp, but as a lesson in why a Lisp variant was suited for this kind of game in the first place.

Interactive fiction with JavaScript

The Web Game Developer’s Cookbook by Evan Burchard takes a different approach. In the chapter on writing interactive fiction, the reader is walked through developing a simple choose-your-own-adventure game using the impress.js presentation library. I’ve used impress.js for slides and I like it a great deal. It wouldn’t have been my first choice for an IF engine, but I can see the value in starting with something that already models a page-like approach.

Again, Twine would be a better choice for implementing a game like this for real, but as a teaching tool, it’s fun and effective:

Screen Shot 2013-11-24 at 4.23.05 PM

One advantage of using a browser engine is that multimedia effects are trivial to implement.

Last but not least, Python

Python is my language of choice, so I’d have been remiss to not include at least one example of using Python to write a text-based game. Luckily, the example comes from one of the best books on learning the language that we have in Safari Flow: Learn Python the Hard Way, by Zed Shaw.

Zed’s example won’t take you through writing an entire game, but it does teach you the basics of accepting user input in Python. The book is a very gentle introduction to programming, and a complete interactive fiction implementation would be a lot for a total newbie to take on.

Screen Shot 2013-11-24 at 4.25.59 PM

Even if interactive fiction isn’t your thing, I strongly encourage anyone thinking about learning to code to come up with a simple project that you’ll find motivating. It should be achievable, just a little out of your comfort zone, and fun.

Tags: coding, Dinosaurs, inform, interactive fiction, Javascript, Learning, lisp, Python, twine, zil,

Comments are closed.