WelcomeWhat's NewsORLibraryDownloadsLinksWebMaster@OnyxRing.com

This site
pageviews since

Today's date:

Author: Jim Fisher
Title: Starting Point

Creation Date: 8/6/2004 10:38:41 PM
Last Updated: 8/6/2004 10:38:41 PM

A Starting Point

here's a program that predates all other programs. It was written before Windows or X, before DOS or BSD, before even CP/M or TRS-DOS. It predates the PC entirely. You can find flavors of it written in every programming language in existence. From assembler to SQL, BASIC to C, Pascal to Fortran, Inform is no exception. Every programmer in the world has typed in a variation of this program. Some versions of it are complex. Others are simple. All share a common purpose: To provide the coder with a an introduction to a programming language. What is its name? "Hello World."

Several "Hello Worlds" exist for Inform already. Probably the most viewed of these was written by Graham Nelson, the author of the Inform language, and can be found in section 1.2 of his "Inform Designer's Manual." It is essentially what follows:

     !This code was snatched from G. Nelson's 
     !Designer's Manual 3 sect 1.2
          print "Hello World!^";

It is not all that inspiring, perhaps, but it does compile and when run, it does exactly what you would expect it to: It prints the words "Hello World!" on the display and then exits.

For a newbie Inform developer, there are several things that can be learned or deduced about Inform from the above example:
     1) An exclamation point precedes comments.
     2) A method or routine is enclosed in brackets and 
          followed by a semicolon.
     3) The method declaration (the name of the routine and 
          parameters) is the first line of code inside the brackets.
     4) Like C, all lines of code end in semicolons.
     5) Also like C (there are numerous similarities between C and 
          Inform), all Inform programs have acommon entry point 
          method (or routine), named "Main."
     6) Additionally, this program gives us a glimpse of a basic 
          Inform routine called "print" which will output 
          data to the display

Perhaps I expect too much from a "Hello World" program, but I also feel that there are also several things missing from that code that keep it from being a good starting place for 99% of developers (In its defense, the example was not really intended as a starting place. Mr. Nelson's finer example appears at the start of the DM's third chapter).
     1) The standard library is completely missing from the example. 
     2) There are not sample rooms for the player to be located in.
     3) There are not sample objects for the player to interact with.
     4) There is no prompt for the player to type in commands.

In theory, you could implement 2, 3, and 4 without implementing the standard library, but in reality you just don't. Why you ask? Simply put, the wheel is already in existence. There is no reason to invent a new one from scratch. The standard Inform library contains all things common among adventure games, including rooms, objects, and input routines. C coders can think of it as the C runtime library. A developer could choose to not use it and rewrite all the standard routines such as "printf," or "scanf" from scratch using the "_asm" keyword and low-level assembler code, but why? Even though they are different, C and the C library are essentially the same thing. The same is true for Inform and the Inform library.

So how do you reference the Inform library? Through includes. The inform library is just code. It exists in a collection of files and you include it by including the three main files in your source file via the include keyword (again, very much like C). These three files are "Parser.h", "VerbLib.h", and "Grammar.h" (on some machines the .h extension is dropped). Saddly, the placement and order of each of the files is significant and has an impact on whether or not your source code will compile.

The library looks for and expects certain things. Certain constants such as "Story" and "Headline" are used to define information about your game. Additionally, the Inform entry point has already been defined in the library. Now a routine named "Initialise" is expected for game initialization.

What follows is a "Hello World" program, which can serve as a starting point for coding any game. I personally keep a variation of this file stored in a "reuse" directory on my personal machine and copy every time I write a new game. Feel free to cut and paste it and change it to suit your preferences. Additionally, there is a slightly modified version of this that will serve as the starting point for many examples in later articles. It can be found here.

     Serial "000001";
     Release 1;
     ! Hello World 
     ! General defines
     Constant Story "Hello World"; 
     Constant Headline "^Copyright (c) 2001: Jim Fisher^"; 
     #Include "Parser"; 
     #Include "VerbLib"; 
     ! Maps 
          object PlainPlace "Plain Place"
               with description "There really isn't 
                    much here. Just a room with no exits." 
               has  light
     ! Movable Objects 
          object     disc "small disk" PlainPlace 
          with       name "small" "disk"
          ,          description "Engraved in this small disk 
                     are the words: ~Hello World!~"
     ! Code 
          location = PlainPlace;
     #Include "Grammar"; 

Copyright 2004 - 2017 : Jim Fisher
OnyxRing.com has been given the potentially non-exclusive right to display the content of this article. However the original author retains all rights. Permission to reproduce this article -- either in part or in whole -- is left strictly to the discretion of the original author.

Table of ContentsAuthorsSearchIndex
Would you
recommend this
article to
someone else?
You bet I would! Heck No!