CODING ★ 10. EXPRESSIONS IN AKS ★

Writing Adventure Games on the Amstrad - 00 - ContentsWriting Adventure Games on the Amstrad - 10 - Expressions in AKS
 ★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se le presenta en su versión original ★ 
 ★ Dieser Text wird in seiner ursprünglichen Fassung Ihnen präsentiert ★ 

At certain points in AKS you may wish to attach a condition to something. If the condition is true then some operation is performed otherwise it is not. When writing an adventure game scenario in Basic a condition can be expressed as an “IF condition THEN perform operation” statement. AKS aims to do away with the need to write in Basic in order to specify your scenario and so cannot use this technique. However, the need for some form of conditional testing when specifying an adventure game cannot be overlooked. How could the puzzle with the big green snake barring the way of the player be implemented if the scenario were unable to test if this puzzle had been solved. Obviously, AKS must have conditional testing. A glance at the scenario definition for WITCHHUNT will reveal the presence of a large number of asterisks at various positions in the definition statements. Each of these may be followed by a string of characters terminated by the end of the line or by a comma. The absence of this string represents the absence of any condition — i.e. the associated operation is unconditional.

 

As in Basic, an AKS condition may have the value of true (T) or false (F). If the condition is true the operation is performed. An IF statement which only allowed you to say “IF T THEN ...” or “IF F THEN . . . ” would be useless. To be of use the condition must be allowed to be something which is evaluated to either T or F. At the simplest level this could be a flag variable. For example, a flag variable could be set aside to indicate whether or not the snake puzzle has been solved. AKS has flags called F0, F1, F2 . . . and so on. Supposing we have allocated F10 to represent the snake puzzle then we can write the condition as *F10. AKS initialises all flags to F at the start of a game. When the player solves the puzzle the scenario assigns the value T to F10. The AKS coding for the snake puzzle could be implemented by defining the appropriate location (18) as follows :

DATA L, 18
DATA D, *, You are in the Hall of the Mountain King.
DATA D, * F10, A large green snake bars your way ahead!
DATA T, release bird, *
DATA A, PR, The bird drives the snake away.
DATA A, AF, 10, T

When the player first arrives at this location he will be greeted by the following description:

You are in the Hall of the Mountain King.

A large green snake bars your way ahead!

The player can now drive the snake away by entering the command "RELEASE BIRD” to which AKS will respond:

The bird drives the snake away.

The AssignFlag (AF) command then sets F10 to T indicating that the puzzle has been solved. Now the description of the location will appear as just:

You are in the Hall of the Mountain King.

This is fine but there is nothing there which states that the player must be carrying the bird in order to release it. Another test is required to replace the unconditional indicator at the end of the trigger line. One possibility would be to set a flag to T when the player catches the bird and test this as we did for the snake puzzle. However, you then have to remember to reset the flag to F if the player drops the bird. A neater solution is to have a function which tests to see if the object is being carried by the player and becomes T or F accordingly. This type of function is called a predicate and can be tested in a similar way to a flag. So that C0, C1, C2, . . . indicate whether objects 0, 1, 2, ... are being carried. Therefore, if the bird is object number 3, the snake puzzle coding can be updated to:

DATA L, 18.
DATA D, *, You are in the Hall of the Mountain King.
DATA D, * F10, A large green snake bars your way ahead!
DATA T, release bird, * C3
DATA A, PR, The bird drives the snake away.
DATA A, AF.10, T

AKS supports six different types of predicates and flags for use in expressions. With the exception of the flag type discussed earlier, the AKS program maintains the necessary information to return a value of T or F for each of these tests. The flag variables F0, F1, F2 . .. are only altered by actions in the scenario definition and their meaning is decided by the scenario designer. The AKS predicates and flags are listed below:

Cx.........Carrying object x
Fx .........Flag x
Lx .........at Location x
Ox.........Object x at current location
Wx.........Wearing object x
Vx .........Visited location x

Although these flags and predicates allow a number of tests to be performed it is often useful to be able to invert the result of a test. The operator “NOT" allows you to do this in Basic. The "NOT" of true is false and vice versa. AKS uses a minus sign to perform the same operation. For example, -C3 can be used to test for the bird not being carried and to print an appropriate message if you try to release it:

DATA L, 18
DATA D, *, You are in the Hall of the Mountain King.
DATA D, *F10, A large green snake bars your way ahead!
DATA T, release bird, *C3
DATA A, PR, The bird drives the snake away.
DATA A, AF, 10, T
DATA T, release bird, *-C3
DATA A, PR, Good idea, but you don't have it.

In addition to the "NOT" operator, Basic conditional expressions allow the use of "AND” and "OR” to construct complex tests. AKS uses the symbols for "AND” and V for "OR”. So far there is nothing in the example scenario location to stop the player passing the snake even though he has been told his way is barred. This requires that all the connections from this location except up (U) which is the way back out of the location, only be opened when F10 is T:

DATA L, 18
DATA D, *, You are in the Hall of the Mountain King.
DATA D, *F10, A large green snake bars your way ahead!
DATA T, release bird, *03
DATA A, PR, The bird drives the snake away.
DATA A, AF, 10, T
DATA T, release bird, *-C3
DATA A, PR, Good idea, but you don't have it.
DATA C, N, *F10, 17
DATA C, E, *F10, 12
DATA C,W, *F10, 25 DATA C, U, *, 5

This has defined the connections north, east and west to locations 17, 12 and 25 to be open only when the snake has been driven off. Now, let us introduce another problem the player is faced with at this location. Once the snake is disposed of, the player is free to explore the connected locations and is able to find three treasures. However, certain of these treasures are too large or heavy to carry up the stairs from the Hall of the Mountain King together. If the player is carrying the gold bar (object 4) and the axe (object 5) or alternatively, the gold bar and the jewels (object 6) and wearing or carrying the armour (object 7) then he may not go up. This can be expressed by:

DATA L, 18
DATA D, *, You are in the Hall of the Mountain King.
DATA D, *F10, A large green snake bars your way ahead!
DATA T, release bird, *C3
DATA A, PR, The bird drives the snake away.
DATA A, AF, 10, T
DATA T, release bird, *-C3
DATA A, PR, Good idea, but you don't have it.
DATA C, N, *F10, 17
DATA C, E, *F10, 12
DATA C,W, *F10, 25
DATA C, U, *-((C4.C5)/(C4.C6.W7/C7)), 5

AKS evaluates conditional expressions starting with the highest priority operators first unless brackets specify otherwise, as does Basic. The priority of operators in descending order are - (not), / (or), . (and). So in the above example the order of evaluation is:

< a > (C4. C5)
< b > W7/C7 "/" is higher than
< c > C4. C6
< d > result of < c > . result of < b >
< e > result of < a > / result of < d >
< f > - result of < e >

★ YEAR: 1985
★ AUTHORS: Mike Lewis & Simon Price

Page précédente : Writing Adventure Games on the Amstrad - 09 - Locations, objects and events in AKS

CPCrulez[Content Management System] v8.75-desktop/c
Page créée en 074 millisecondes et consultée 64 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.