Sunday, 3 August 2014

Write interactive fiction

Time it takes: 60 minutes

Text adventure games were massively popular at a time when all computers could do was display text, and there has recently been a strong resurgence in their popularity thanks to mobile devices. The games eat few CPU cycles, burn very little power and don't require too much dexterity. You don't need to be a coding guru to write one either: the games are programmed using a form of natural language. For example, the game parser will understand the name and relative positions of the two locations described by the line 'The library is west of the landing.' This makes developing games almost as much fun as playing them. Secondly, there's a brilliant development environment that can help you map out the ideas and locations for your game, as well as help you enter and understand the source code. And to show just how easy it is, we're going to create the beginnings of an interactive masterpiece.

Install the IDE

The IDE is called Gnome Inform, and you'll need to grab packages for your distribution as they're seldom included in the average repository. The project's page on SourceForge includes binary packages for most popular distributions, and there shouldn't be any weird dependencies. Installing the application using a package manager should be a simple point and click process, and it can be executed by either typing gnome-inform7 on the command line, or finding the application hidden within your launch menu.
Games created using Inform 7 can be played on anything from mobile phones to wristwatches.
Games created using Inform 7 can be played on anything from mobile phones to wristwatches.

Get writing!

The main Gnome Inform window is split into two panels, both of which can be switched to display any one of seven screens. Normally, you'd use the panel on the left to type the source code for the game, and the panel on the right for testing the current build, documentation and debugging, but you're free to use each panel as you choose. To create a game, make sure one side has 'Source' selected, and type:
"Wretched Exchange" by "Anonymous Penguin" When play begins:
say "[italic type]It's one of the hottest days of the year. You're stuck in the office trying to get OpenExchange installed on to one of the crusty old Linux servers, and you can't leave until the CEO's Blackberry starts whirring with new email."
The Office is a room. "Why do all offices look alike? There's the low-slung polystyrene ceiling, complete with ambient lighting, and various desks and chairs littered across the lino floor tiles. The server room is to the north and an emergency exit to the south."
This is all you need to create a working title. Gnome Inform knows how to parse this data automatically, taking the title and author from the first line, and the intro text that follows 'When play begins:' But the most essential part of this code is the room description, as locations such as this are the core components within a text adventure. Inform automatically extracts the room description and is able to work out that the server room is to the north while the emergency exit is to the south from the natural language in the description.
Rooms aren't much good without objects, and you can add one to the office atmosphere with the following lines:
A coffee cup is here. The description is "On the inside, the cup is stained black by years of caffeine addiction. The outside sports the image of a penguin."
After taking the cup:
say "Taken. You sure wish you could find some fresh coffee."
After dropping the cup:
say "Dropped. So much for getting a caffeine hit."
In this chunk of text, we're saying there's a coffee cup in the room as well as defining a couple of actions - taking and dropping. Both of these are automatically understood by the parser, but there are going to be times when the parser doesn't understand an action, and in those cases you'll have to create your own. In the server room to the north, we're going to place an air-conditioning unit, and create a new action that activates the unit and solves the game.
The Server Room is a room. It is north of the office. "It's difficult to hear yourself think in here. Racks of servers are humming away, filling the air with an acrid damp humidity."
An air conditioning unit is here. The description is "Attached to the wall, this yellowing unit seems to have been bought on the cheap from the local Pub after the smoking ban made it redundant. Water is dropping from the unit on to the floor."
Activating is an action applying to one thing. Understand "activate [something]" as activating.
Before activating the air conditioning unit:
say "Wow! You turn on the unit and the servers gradually stop complaining.";
end the game in victory.
You can now run the game and complete it by going north and activating the air-conditioning unit. It's a ridiculously simple solution, but you should be able to see the massive potential in the natural way a game can be created. It's designed to feel much like reading a book, and the results can be fantastic.

No comments:

Post a Comment