O'Reilly logo

Gaming Hacks by Simon Carless

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Add Nonplayer Characters to IF Adventures

Populate your virtual world with realistic virtual characters.

Previous hacks have explained how to create, compile, and run an Inform game ( [Hack #85] ), create and manipulate objects ( [Hack #86] ), and challenge the player with puzzles ( [Hack #87] ). That’s enough for an interesting game right there.

Why stop at merely “interesting,” though? If you have fond memories about Infocom’s heydey, you may remember the infamous thief and Dungeon Master from the Zorks, a paranoid android and his contrary door from The Hitchhiker’s Guide to the Galaxy, and the lovable Floyd from Planetfall and Stationfall. What gave these games such character? In part, unforgettable nonplayer characters.

Discovering the Need for a Character

Let’s return to the cyberspace game developed in the previous three hacks. Once you have the identity token, the next step is to give it to the access controller back in Router NP-462, off to the north. Start by walking north:

> n

Router NP-462

What just happened?

First of all, you moved from one room to another simply by typing a one-letter abbreviation for the direction in which you wanted to travel. This is standard practice in IF; typing n at the prompt is exactly the same as typing go north, except for saving keystrokes. Inform handles this behavior automatically.

The program moved back into the original room and notified you of this fact by printing out the name of the room and nothing else. This is the default behavior ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required