Friday, 1 May 2015

Writing a basic game with Inform 7

This series covers the creation of a simple Point and Click style adventure as created using various engines, I am using the term "Point and Click" very loosely since some of the engines I am going to  use are text based.

The set up is simple.  You start out outside a cabin situated in the mountains.  You have to make a fire or else you will freeze to death.  There are two locations: outside and inside the cabin.  Outside the cabin is a pile of firewood.  Inside the cabin is a fireplace and a match.  You need to put the firewood in the fireplace and light it with the match.  Not one of your harder puzzles.

The first engine I am going to demonstrate is Inform 7.  Inform helps you create text based adventures or, more recently, Interactive Fiction or IF.  Version 7 digresses from its predecessors by creating the game using plain English instead of a programming language.

The final version can be played here: (Please note that it includes a JavaScript parser called Parchment that lets you play it in your browser.)

First thing I'm going to do is set up my two locations:

"Light my Fire" by Susan Douglas

Section 1 - Locations

Exterior is a room. "You find yourself outside a small wooden [building] to the west.  The artic [wind] cuts through your clothing sapping what little heat you've managed to conserve."

Interior is west of Exterior. "Cozy is the first thing that comes to your mind when looking around the interior.  Tiny also comes to mind.  There is an open [fireplace] opposite the door and a [table] and [chair] set up by the [window]."

If you tried to run the code as is, you will get a ton of compilation errors:

In the line '"You find yourself outside a small [...] e heat you've managed to conserve."'  , I was expecting that 'building' would be something to 'say', but it didn't look like any form of 'say' that I know. So I tried to read 'building' as a value of some kind (because it's legal to say values), but couldn't make sense of it that way either.


That's because I put brackets around the things I don't want to forget to describe.  This technique is called "BENT" or "Bracket Every Notable Thing" which I learned from Aaron A. Reed's book Creating Interactive Fiction with Inform 7.

So lets go back and describe the things.

The building and the wind are scenery in Exterior.

The description of the building is "The building is merely lumps of logs lashed together.  Small but serviceable."

The description of the wind is "A bitter cold wind that would gladly take you away."

The window is scenery in Interior. "Frost covers the glass, preventing you from looking outside."

The fireplace is thing in the Interior. It is an open fixed in place container. "An open fireplace with layers of soot showing that there have indeed been fires inside of it."

The table is a thing in the Interior.  The table is a  supporter. The description of the table is "A lonely wooden table with the dings and scratches of normal household use."

The chair is scenery in Interior. "A rickety old chair that doesn’t look like it could support anyone."

Your fire is scenery. Instead of pushing, pulling, turning, tasting, or touching your fire, say "You would burn yourself." The description of your fire is "A reassuring protection against the cold."

That’s a pretty good start.

The next thing I did was teach Inform about burning and matches.  I didn’t write this code my self.  I adapted it from one of the examples that comes with Inform 7.  ’m not going to include the code here.   If you want to see it, go to the release page:

I am going to show some of the changes I made.

Check burning something with something (this is the burn only things in fireplace rule):
    if the noun is not in the fireplace, say "[one of]It occurs to you to put  [the noun] in the fireplace before burning, just for safety's sake. [or]Again, you decide to put [the noun] into the fireplace prior to burning. [or]You try setting [the noun] in the fireplace as usual. [stopping]" instead.

I changed the “You can’t be holding the item” rule to “The item has to be in the fireplace”. Now, instead of letting you burn things anywhere but the fireplace.

Carry out burning something with something (this is the simplistic burning rule):
    say "You succeed in lighting yourself a proper fire.";
    end the story finally.

If you succeed at burning anything, the game ends.  By this time I was really tired I didn’t come up with any colour text for the ending.

After teaching about matches, all that was left was to set up the scenario:

Part 4 - Start   

A log is a flammable thing in the exterior. Understand "wooden" and "wood" as the log.

The matchbox is an open openable container. It contains five s-matches. It is on the table.

Every turn:
    say "[one of]The wind howls and cuts right through you[or]You shiver[or]You can feel the cold draining your life force[or]You are going to die without a fire of some sort[then at random].";

I put the flammable log in the exterior. I put the matchbox pull of matches on the table, then I set up some text to appear every turn to let the player know that they are cold and should build a fire.

I’ll admit that this is a pretty skimpy game.  It took me all of about an hour and a half to write and that was mostly getting the matches to work.

Please let me know:

  • Do you want to see this game made in other engines? i.e. Unity, Ren’py. RPG Creator. etc
  • Do you want a video walkthrough of me making the game?
  • Do you want me to give a better description of how and why to use Inform7

Thanks for now.


Other articles in this series:
Making a Basic Game with Inform 7
Sample Game with JSGAM
Making a Basic Game in Twine

No comments:

Post a Comment