3 - Lesson Three


Our sample game will be a bit more interesting if we change the locations to something a bit more realistic than a vague "APlace" and "AnotherPlace". We can change the first location to a city street by renaming the location and changing the text in the DESCRIPTION section.

3.1 - Location Names

We can give the location a more descriptive name so that instead of 'street' being displayed we could have 'A City Street.' by adding a NAME clause after the LOCATION statement.

If you want to use any Alan keywords in the NAME then you need to enclose them in single quote marks.

Arun would display that as 'A Motorway Exit Ramp.'

Remember that if you want the player to be able to refer to the location by name the quoted text must be all in lower case. The player is not likely to use a location name in their commands but this is something to remember when naming objects and actors - which we'll discuss in a later lesson.

3.2 - Special Formatting Characters

Normally, Alan will display any text in a nice tidy block with single spaces between words no matter how it appears in the source code. Sometimes however you may want to have the text formatted a specific way on screen.

This can be done by inserting special control strings in the text. Particularly useful are $n to start a new line, $p for a new paragraph (puts a blank line between paragraphs) and $t to tab (or 'indent') text by four characters.

We could add the following to our "A City Street" DESCRIPTION :

  A sign on the front door says $p$tPrivate
   $n$tThis is my home$n$tDon't Annoy Me!" 

When the game is played this would be formatted on screen like this:

A sign on the front door says

   Private
   This is my home
   Don't Annoy Me! 

3.3 - The Description Section is for more than descriptions

So far in this tutorial we've seen location DESCRIPTION sections containing just a piece of text within double-quotes. Text within double-quotes are actually 'print-this-text-on-the-screen' Alan statements - think of them as PRINT statements with the word PRINT left out.

The DESCRIPTION section of a location definition can also contain other types of Alan statements as well as double-quoted text. For example awarding points to the player for arriving at a location is specified in the source code with a statement added to the DESCRIPTION section for the location.

3.4 - Awarding points to the player

Providing the player with points when they achieve certain goals in the game such as reaching a certain location or rescuing a distressed damsel adds to the interest in the game and provides the player with a measure of how well they are progressing through the game.

Points are allocated to a player with a SCORE statement. For example if SCORE 5 is added to a location description, the player will be awarded 5 points the first time they visit that location.

(If that SCORE 5 statement is executed again, perhaps because the player visits the same location again, then nothing happens. The 5 points is only added to the score once.)

3.5 - Displaying the score

To display the current score use the SCORE statement alone with no number after it. So we could display the score with our quit verb to let the player know how far through a game they are when they decide to finish playing.

The player may also want to know the score while playing the game. So we can create a verb the player can use whenever they want to check their current score. Lets be predictable and call it the 'score' verb! The definition of this verb would then be something like this:

Try compiling and playing lesson3.ala - the lesson three example game. Try entering the score command and then move between locations and try the score command again.


Example Alan source code | Table of Contents | Next Lesson