2 - Lesson Two


2.1 - The first command - "finish" !

Now we have a nice little game but we had better add a command to exit from the game.

Commands the player can use are called "verbs" in Alan. The description of a verb in Alan source code looks like this

The Alan instruction (or 'statement') to stop Arun running a game and return to the computer operating system is QUIT . So if we want the player to be able to enter the command finish when they want to stop playing a game, we would enter the following verb description in our source code file

2.2 - The 'syntax' statement

The stop-playing-the-game verb isn't the simplest first example of an Alan verb. It is mentioned first for two reasons. Firstly, it is a necessary command to finish playing a Alan game. Secondly, it provides an opportunity to introduce Alan's very useful SYNTAX statement.

The problem with our 'finish' verb is that the definition of single-word commands in Alan is more complicated than what I've described so far. (If you've rushed ahead and tried compiling that command already you will have found that Alan produced a warning message when it compiled the source code.)

This is because most verbs in adventure games do something to an object. Examples would be "eat cake" or "get the cloak." So Alan, by default, expects verbs to be followed by another word which is the name of an object. (Don't worry if you don't know about objects - we don't talk about them for another few lessons.)

If we played our example game as it is now and entered the command finish Arun would reply "I don't understand" because Arun would be expecting another word after finish. This is because Alan would have compiled the game assuming that finish would always be followed by the name of an object - that's what the 'warning' message would've said. So we need to tell Alan that the verb finish makes sense as a single word command. This is done with a syntax statement which would simply look like this:

This means the player will invoke the verb named on the left of the equals sign by typing the word, or words, on the right of the equals sign. For a single word verb like finish the syntax statement looks a little trivial. The syntax statement is, however, a powerful feature of Alan which is also used to tell Alan games how to interpret complicated phrases like 'pour the water from the bucket onto the campfire.'

So the complete definition of our stop-playing-the-game verb would look like this

2.3 - Verbs with the same name as Alan Statements

In adventure games the verb to finish playing a game is traditionally called quit. Most other types of software would use exit but this word could be used during an adventure game to, for example, leave a room so exit is not normally used to end a game. You could call your finish-playing-the-game verb anything you like but we will stick with tradition and use quit.

To make a command called quit available to the player we need to create a verb statement in our source code like this:

This means that when the player types quit the Arun program will execute the Alan statement QUIT. Coincidentally, the verb-name and the statement happen to both be 'quit'

Note that word quit has single-quote marks around it when used as a verb-name. This is because if the word was written without quotes as we did with the definition of our finish verb, Alan would assume the word was the Alan statement QUIT and putting an Alan statement next to the VERB statement makes no sense to the Alan compiler.

Similarly we need to use quotes in the syntax statement for the quit verb.

Note that text within single-quote marks should always be entered in lower-case. (The reason for this is explained in the "Tutor's Ramble" below.)

2.4 - A complete adventure is now written !

Well that's it. We have now written the source code for a playable Alan text adventure game with two locations the player can move between and a command to quit the game.

Compile the example source code for lesson two and add a "quit" command to your own example game.


Example Alan source code | Table of Contents | Next Section