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.
LOCATION Street DESCRIPTION "Either side of the street is full of shops. The shops are a typical mixture of old houses converted into trendy boutiques and a few new glass-fronted shopping arcades. The exception is one house, to the north of you, which looks like a deserted house." EXIT north TO Porch. END LOCATION.
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.
LOCATION Street NAME A City Street
If you want to use any Alan keywords in the NAME
then you need to enclose them in single quote marks.
LOCATION Street NAME A motorway 'exit' ramp
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.
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!
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.
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.
LOCATION Porch NAME Front Porch DESCRIPTION "The unpainted wood of the porch is rotting and feels like it could crack under your weight at any moment. The front door of the house, however, seems newly installed and very strong." SCORE 5. EXIT south TO Street. END 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.)
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.
VERB 'quit' DOES SCORE. QUIT. END VERB.
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:
SYNTAX 'score'='score'. VERB 'score' DOES SCORE. END VERB.
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.