ADL (which stands for "Adventure Definition Language") is a programming language and run-time environment designed for the convenient implementation of Adventure-like games. This document describes ADL and is intended for the use of a programmer who wishes to create such a game.
The authors would like to acknowledge the
tremendous influence of the earlier language DDL
from which ADL was derived. DDL was created in
1981 by Bruce Adler, Chris Kostanick, Michael
Stein, Michael Urban, and Warren Usui, then
members of the UCLA Computer Club. For information on DDL, please consult the document "A Brief
Description of UCLA Dungeon Definition Language
(DDL)" written by the creators of DDL and available from the University of California.
June 19, 1987
Computer games have existed for nearly as long as computers have existed. One of the most popular computer programs of all time is Adventure. In Adventure, the player is placed inside a world which exists only in the memory of the computer (and the mind of the player). The player interacts with this world by means of English-like sentences. Objects that the player finds may be taken, opened, closed, tasted, thrown, and otherwise manipulated.
Previously, most programmers attempting to write their own Adventure-like game have been bogged down by such trivial details as implementing a parser for player input, properly responding to the player's commands, and dealing with the passage of time. ADL is intended to relieve the programmer of such worries and to allow the programmer to concentrate on the important details of the imaginary world. The following is a short excerpt from the play of a game which was written in ADL:
Red room. You are in a large room which is illuminated by a bright red glow. Exits lie to the east and south. > Go east. Green room. You are in a smallish room which is illuminated by a pleasant green glow. The only exit is to the west. There is a robot here. > west Red room. > s Blue room. You are in a tiny room which is barely illuminated by a dim blue glow. There is an exit to the north, and you seem to make out something on the floor. There is a button on the wall. Above the button is a sign that reads: DANGER! HIGH VOLTAGE! > n Red room. > e Green room. You can see: a robot > Tell the robot "Go west then south. Push the button then go north." "Sure thing, Boss." The robot exits to the west.
Notice that this script demonstrates powerful features not present in many other Adventure-like games. This document will describe the utilities and "tricks" necessary to write games such as the above.
Structured data types are the heart of any structured language. ADL is not lacking in structured data types. It is through the proper definition of specific instances of these data types that the ADL programmer defines a scenario. Note that all data types in ADL are represented by sixteen-bit integer IDs. Although there is little facility for producing user-defined data types, the power of the existing set makes it unlikely that such would be required for any reasonable scenario.
As in most Adventure-like games, the most important data type in ADL is the Object. An object in real life can be a person, place, or thing. ADL models the world in the same way. Any Object encountered by the player is represented by this type, as are all locations in the scenario. Indeed, there can be Objects associated with people (more on that later). Notice that ADL treats all Objects uniformly and so it is possible to write a scenario in which a player picks up an Object (a tent, say), carries it around, and later enters it.
All Objects are represented by (unique) sixteen-bit integers. This number is known as the "Object ID" of the Object. Objects are (essentially) record structures with the following elements:
All Objects in ADL are stored in a tree. The root node of the tree is predeclared and is named ".ALL". Its Object ID is always zero. All other Objects are ultimately located in .ALL.
Two other predeclared Objects exist. One is named "STRING" and the other is named ".ME". .ME is not truly an Object -- it is more like a variable which represents the current Actor during the execution of an ADL program (more on Actors in Section 3.1). It is illegal to use .ME outside of the context of a routine. STRING is the Object which is seen by the ADL program when the run-time sentence parser encounters a string. Note that although STRING is predeclared by ADL, the properties of STRING must be defined by the ADL programmer. See Chapter 9 for more information on STRING.
Verbs are the means whereby a player manipulates the environment. Verbs can denote motion, investigation, manipulation, and any other action the ADL programmer can imagine. A Verb is represented by a sixteen-bit integer known as the Verb ID. Like Objects, Verbs are record structures. They have the following elements:
Verbs may also be used as modifiers to nouns. This is to allow easy implementation of Objects like the "north wall" or "go north" (where "north" is normally a verb of motion).
ADL predeclares the two Verbs "TELLER" and "NOVERB" which are returned by the parser under circumstances shown in Chapter 9. Although TELLER and NOVERB are predeclared, their properties must be defined by the ADL programmer.
Adjectives serve only one purpose: to disambiguate otherwise identical nouns (such as a "red ball" and a "blue ball"). Adjectives have no structure and exist only as sixteen-bit Adjective IDs.
There are two forms of strings in ADL: compile-time strings and run-time strings. Compile-time strings are those which appear in the ADL source code for the scenario. They are delimited by double quotes and are transformed into positive sixteen-bit String IDs by the compiler. These strings are free-form in that a carriage return may appear in them at any point. This sort of carriage return is transformed into a blank. Should the ADL programmer desire a true carriage return, the sequence \n should be embedded in the string at the appropriate point. Compile-time strings may be limited to 255 characters in length in some implementations.
Run-time strings are those which are typed by the player and those which are generated by the built-in string manipulation routines. Strings in player input may be delimited by appropriately nested single or double quotes. All run-time strings are represented as NEGATIVE sixteen-bit string IDs.
There are two forms of numbers in ADL: compile-time numbers and run-time numbers. Compile-time numbers exist in the ADL source code for the scenario and may be any integer in the range of -32768 to 32767 inclusive. Run-time numbers are those which are typed by the player. Run-time numbers are transformed into a string consisting of the ASCII representation of their digits. A negative string ID is then returned for eventual use by the ADL program.
Routines in ADL are represented by (what else?) sixteen bit Routine IDs. The only operations allowed on routines are calling them and passing them to other routines as parameters. The syntax of ADL routines is described in Chapter 6. The routine "START" is predeclared by ADL and must be defined by the programmer or execution will be prematurely terminated. The Routines "DWIMI" and "DWIMD" are also predeclared by ADL and should be defined by the programmer. DWIMI and DWIMD are called under circumstances detailed in Chapter 4.
There are a number of global variables available for definition and use by the ADL programmer. A global is represented by a sixteen-bit ID and may hold any integer value from -32768 to 32767. These values may be interpreted as simple numbers, String IDs, Routine IDs, Object IDs, Verb IDs, etc. depending upon how they are used. The globals named Verb, Conj, Numd, Dobj, Prep, and Iobj are predeclared by ADL and at run-time contain the values of the current Verb, Conjunction, Number of Direct Objects, Direct Object, Preposition, and Indirect Object, respectively.
The ADL programmer may declare a block of global variables for use as an array or list of things. See Chapter 5 for more information.
Local variables differ from global variables in that their name is limited in scope to the routine in which they appear. They are represented by sixteen-bit IDs which may be passed to other routines if desired. Local variables may be implemented in one of two ways: on the stack (like local variables on C and Pascal) in which case they are only around for as long as the current invocation of the routine; or they may reside in the same space as global variables (like static locals in C or local variables in FORTRAN) in which case they persist for the entire duration of program execution. Consult your local ADL documentation to determine which method is used in your implementation.
A modifier is simply a word that modifies an ambiguous noun to produce an Object. A modifier may be either a Verb or an Adjective. If the modifier of an Object is a Verb, it is represented as the NEGATIVE of the Verb ID. If it is an Adjective it is represented by the (positive) Adjective ID. If the modifier is zero, the Object has no modifier.
ADL maintains several internal structures to achieve the level of interaction necessary for interesting play. These structures are accessible only through the built-in routines described in Chapter 7.
In a typical adventure game it seems as if the player is moving around the dungeon taking things, smelling them, breaking them, and so on. A better model would be that the player is giving commands to an actor. It is the actor which actually moves around, collects items, and otherwise acts. It is this model which ADL follows.
An Actor is essentially an "animate" object which acts upon commands given to it. Notice that there is nothing in this model which prevents more than one Actor from running around a scenario. In fact, in ADL there may be up to ten Actors which are active at any one time.
There are two kinds of Actors: interactive and non-interactive. The player is an example of an interactive Actor. Commands are read directly from the keyboard and placed in a line buffer which is then passed to the parser and interpreter. When the line buffer is empty a new one is read from the keyboard. Any number of Actors may be interactive, making multiple player games a possibility.
The robot in the introductory script is an example of a non-interactive Actor (see Appendix 2 for the source to the scenario which produced that script). The line buffer for the robot was initialized after the player typed the sentence starting with "Tell the robot ...". The robot then acted on this command by performing the requested actions in parallel with the actions of the player. This means that each Actor gets one turn for each turn that the player experiences. A non-interactive Actor is deleted from the list of active Actors when its line buffer is emptied.
There is a special object-like item named ".ME" used to implement this sort of "multiprocessing". .ME represents the Object ID of the current Actor for the purposes of moving around, taking things, etc. Anything that the player can do can be done just as well by another Actor. This is probably the most powerful (and most obscure) feature of ADL.
Actors may be activated using the $actor built-in routine and deleted at any time by using the $delact routine.
Daemons are routines which execute once for each active Actor at the beginning of each turn. Daemons are typically used for things like describing the player's location and incrementing the turn counter. Daemons are activated by using the $sdem routine and may be de-activated by using the $ddem routine. Up to ten daemons may be active at one time.
Fuses are routines which wait a certain amount of time, execute, then become inactive. The list of fuses is examined each time the turn counter is incremented to see whether any have "burned down". If so, the fuse is executed and deleted from the list.
Fuses are typically used for things like waiting three turns and then collapsing the room that the player was in, or (the bane of all adventurers) running down the batteries in a lamp. Fuses are activated by using the $sfus routine. Up to ten fuses may be active at one time. The $dfus routine may be called if the programmer wishes to delete a fuse before it executes (the player found more batteries!).
Many times during the play of the game it is desired that a player enter a line from the keyboard. Some sort of prompting should be done in order to inform the player that input is desired. The ADL programmer may specify a Routine ID to do this prompting. This routine is known as the prompter and is set by using the $prompt routine.
Normally when the parser gets its input from the line buffer of the current Actor, the words are what they seem to be: simple words. ADL has a facility whereby these words may be transformed before the parser sees them. Each word is looked up in a table (the "macro table"). If found it is replaced by the expansion for the macro (which may be a string containing more than one word) and re-inserted into the line buffer whereupon the input process continues.
One use of this facility is to "rename" objects. For
example, it may be desired that the player be able to type
something like "Name the box 'bob'. Take bob." (notice that
the second usage of bob has no quotes). This can be accomplished by the call ($define "bob" "box")
which says to
expand "bob" to "box" whenever it is encountered in the line
buffer. The built-in routine $undef may be used to "undefine" a macro if it outlives its usefulness -- for example
($undef "bob")
removes "bob" from the macro table. More is
said about macros in Section 7.10 under the entries for
$define and $undef.
The flow of execution of the game can be described now that the basic data types have been defined. The execution starts with an initialization step: an ADL routine named START is called. ADL terminates prematurely if START has not been defined. START typically activates the principal Actor (the player) and a looker daemon (responsible for describing the player's surroundings), initializes the prompter, and so on. ADL then enters a loop from which it never returns (until program termination).
The main loop of the game consists of a series of phases. The built-in routine $phase will return the number of the phase currently executing (see the flow diagram and Section 7.12 for the number of each of the phases). At the beginning of each turn, all active Daemons are executed for each Actor on the Actor list -- in the REVERSE order in which the Actors were activated. This is so newly activated Actors don't act before the older Actors have a chance to act. The Daemons are executed in the order in which they were activated.
After all Daemons have executed for all Actors, a series of phases are executed for each Actor on the Actor list (in the reverse order of Actor activation). The loop progresses downward in an orderly fashion unless interrupted by a call to $exit. For information on $exit see Section 4.2. The following are the phases which are executed for each Actor on the Actor list:
It is possible to change the normal flow of execution
by means of the $exit built-in routine. The programmer may
use ($exit 0)
to halt execution of the current phase and
move on to the next phase. At any time, ($exit 1)
may be
used to halt the execution of the current phase and skip to
the next Actor. Inside the Direct Object loop, ($exit 2)
may be used to skip the rest of the Object and Verb ACTIONs
and go on to the next Direct Object in the list. At any
time after the parsing phase, ($exit 3)
will return the flow
of control to the Parsing phase without clearing the sen-
tence. This allows for incremental entry of sentences; for
example "The big door. Unlock. With the key".
The following is a diagram of the flow of execution: START [0] | v +--------------------------------->o | | | v | Daemons [1] | | | v | Get Actor <----------------------+ | | | | v | | +------------------> Clear Sentence | | | | | | | v | | | ($exit 3)====> Get Input? --n---> Delete Actor | | | | y | | | | v | | | o<---------------------- Parse? | | | ^ | | | | | v | | | o<-------------fail----- DWIMI | | | ^ | | | | | v | | | +--------------fail----- DWIMD | | | | | | | v | | | Get Dobj <-------+ | | | | | | | | v | | | | Actor ACTION [2] | | | | Verb PREACT [3] | | | | Iobj ACTION [4] | | | | Dobj ACTION [5] | | | | Verb ACTION [6] | | | | | | | | | v | | | | ($exit 2)===> More Dobjs? -y----+ | | | | n | | | v | | | Room ACTION [7] | | | | | | | v | | | ($exit 1)=========>o<-------------------+ | | | | | v | +--------------------------n- More Actors? -y-------------------+
This chapter describes the format of ADL programs. An ADL program consists of a list of one or more of the following statements. Comments in ADL programs are delimited by { and }. Since case is significant in ADL, tokens which are identical except for differing case are different (for example, "noun" is not the same as "NOUN").
Note: for a full BNF specification of ADL programs, see Chapter 8.
Example: INCLUDE "standard.adl";
Example: MESSAGE "Whew! We're halfway through the file!\n";
($setg ($plus Array 10) 5)
is similar to Array[ 10 ] = 5
in C.
Example: VAR Score, Dark, ObjList[ 10 ], MyLoc;
Example: VERB take, drop, open, close;
Example: ADJEC red, green, blue;
Example: NOUN room1; NOUN table( room1 ), chair( room1 ), red ball( room1 );
Example: ROUTINE Looker, Prompter, Quitter;
Example: ARTICLE the, a, an;
Example: PREP in, into, on, above ;
Example: room1( LDESC ) = ($say "You are in a huge room.\n") ; chair( WEIGH ) = 450 ; table( MESSAGE ) = "This space for rent\n" ;
Example: take( ACTION ) = ($say "You can't take that object.\n"); drop( PREACT ) = (CheckAvail);
Example: MagicWord = "AbraCadabra"; { string ID } VISIT = 3; { constant } Silly = ($say "That's silly!\n"); { routine ID } toolbox = tool box; { object ID }
Example: ( MyLoc ) = -1; ( Score ) = 10;
Example: VAR foo[ 10 ]; ( foo ) = 3; { Sets foo[0] to 3 } ( foo + 5 ) = 6; { Sets foo[5] to 6 }
Example: PREP in, of, before; NOUN front; in front of = before;
Example: VERB put, take, turn, wear, remove, light, douse; PREP on, off; put on = wear; take off = remove; turn on = light; turn off = douse;
This chapter describes the syntax of ADL routines. An ADL routine consists of an optional LOCAL declaration fol- lowed by a sequence of one or more expressions. An expression is one of the following:
( IF arg1 THEN expression ... ELSEIF arg2 THEN expression ... ... ELSE expression ... )This statement evaluates arg1 and if the result is non-zero the expressions following THEN are executed. If the result of the evaluation of arg is zero then the expressions following THEN are skipped until one of ELSE, ELSEIF or the end of the conditional are found. If ELSEIF was found the corresponding arg is evaluated and execution proceeds as for IF. If none of the ELSEIFs evaluate to a non-zero value then the ELSE expressions are executed. The ELSEIFs and the ELSE are optional. The conditional expression returns the value of the last expression executed or zero of no expressions were executed.
{ A sample looking daemon } Look = LOCAL obj; ($incturn) { Increment the turn counter } (IF ($prop ($loc .ME) VISIT) THEN { I've been here before - print a short description } ( ($sdesc ($loc .ME)) ) ELSEIF ($ne ($cont ($loc .ME)) .ME) THEN { There are other objects here } ( ($ldesc ($loc .ME)) ) ($say "You can see:\n") ($setg obj ($cont ($loc .ME))) (WHILE @obj DO { Describe each object in the room } ( ($sdesc @obj) ) ($setg obj ($link @obj)) ) ELSE { I've never been here } ( ($ldesc ($loc .ME)) ) ($say "There is nothing else in the room.\n") ) ($setp ($loc .ME) VISIT TRUE) ;
The following is the complete list of ADL built-in routines. They are organized into groups of related routines. A description of each routine is provided with at least one example to clarify its usage. The following groupings of built-in routines are detailed in this chapter:
These routines operate primarily on Objects. They move Objects around, find Object properties, and set Object properties.
( $loc obj ) ->
The location of obj.
Example: (IF ($eq ($loc .ME) volcano) THEN ($say "You are fried to a crisp.\n") )
( $cont obj ) ->
The first object which is contained
in obj.
Example: (IF ($eq ($cont .ME) 0) THEN ($say "You are empty-handed.\n") )
( $link obj ) ->
The next object contained in the
same location as obj.
Example: ($setg obj ($cont .ME)) (WHILE @obj DO ($say ($name @obj) "\n") ($setg obj ($link @obj)) )
( $ldesc obj ) ->
The long description of obj. This
is equivalent to ($prop obj LDESC)
. Since this is a
Routine ID, it is typically used as the callee in a
routine call.
Example: ($setg obj ($loc .ME)) ( ($ldesc @obj) ) { Call LDESC of ($loc .ME) }
( $sdesc obj ) ->
The short description of obj.
This is equivalent to ($prop obj SDESC)
. Since this
is a Routine ID, it is typically used as the callee
in a routine call.
Example: ($setg obj ($loc .ME)) ( ($sdesc @obj) ) { Call SDESC of ($loc .ME) }
( $action obj ) ->
The ACTION routine of obj. This
is equivalent to ($prop obj ACTION)
. Since this is
a Routine ID, it is typically used as the callee in
a routine call.
Example: ( ($action .ME) ) { Call ACTION of .ME }
( $modif obj ) ->
The modifier of obj. This is zero
if there is no modifier, negative if the modifier is
a Verb, and positive if the modifier is an Adjective.
Example: (IF ($eq ($modif [ blue ball ] ) blue) THEN ($say "$modif works!\n") ) (IF ($eq ($modif [ north wall ] ) ($minus 0 north)) THEN ($say "$modif still works!\n") ) (IF ($eq ($modif room1) 0) THEN ($say "$modif comes through one more time!\n") )
( $prop obj num ) ->
The numth property of obj.
Example: ($setg obj ($loc .ME)) (IF ($prop @obj VISIT) THEN ($say "I've been here before!\n") )
( $setp obj num val ) ->
No return value. Sets the
numth property of obj to val.
Example: ($setg obj ($loc .ME)) ($setp @obj VISIT TRUE)
( $move obj loc ) ->
No return value. Moves obj to
loc. WARNING: Do not attempt to violate the tree
structure of objects (e.g. ($move .ALL foobar)
) or
horrible and unpredictable things will happen.
Example: (IF ($eq @Verb north) THEN ($move .ME room2) )
These two routines operate on Verbs. They are provided for scenarios in which the properties of Verbs may change.
( $vset verb prop val ) ->
No return value. The pro-
perty prop of verb is set to val. Prop must be
either PREACT or ACTION.
Example: ($vset @Verb PREACT Silly)
( $vprop verb prop ) ->
The value of property prop
of verb. Prop must be either PREACT or ACTION.
Example: { Call Verb's PREACT } ( ($vprop @Verb PREACT) )
These routines operate on arbitrary sixteen-bit numbers, and return sixteen-bit values. Note that the numbers may actually be Object IDs, global variable IDs, or any of the sixteen bit IDs used by ADL.
( $plus num1 num2 ) ->
Returns num1 + num2.
Example: ($setg Score ($plus @Score 50))
( $minus num1 num2 ) ->
Returns num1 - num2.
Example: ($setg LivesLeft ($minus @LivesLeft 1))
( $times num1 num2 ) ->
Returns num1 * num2.
Example: ($setg TimeLeft ($times @NumBattery 10))
( $div num1 num2 ) ->
Returns num1 / num2.
Example: ($setg Rating ($div @Score 100))
( $mod num1 num2 ) ->
Returns the remainder which
results when num1 is divided by num2 according to
normal integer division.
Example: { Make sure XPos is from 0 to 9 } ($setg XPos ($mod @Xpos 10))
( $rand num ) ->
Returns a random number from 1 to
num inclusive.
Example: { Move the player to a random room from room1 to room10 } ($setg Num ($rand 10)) ($move .ME ($plus room1 ($minus @Num 1)))
These routines are typically used in conditionals and loops. However, traditional bit-masking may be done with $and and $or.
( $and a b c ... ) ->
Returns the bitwise AND of the
vector a b c .... Note that since this is the bit-wise AND, care must be taken in conditions since
ANDing two non-zero values does not necessarily
return a non-zero value.
Example: ($and 2 4) is 0 (0b0001 AND 0b0010 = 0b0000) ($and 3 7) is 3 (0b0011 AND 0b0111 = 0b0011) ($and 1 1) is 1 (0b0001 AND 0b0001 = 0b0001)
( $or a b c ... ) ->
Returns the bitwise OR of the
vector a b c ....
Example: ($or 0 0) is 0 (0b0000 OR 0b0000 = 0b0000) ($or 1 2) is 3 (0b0001 OR 0b0010 = 0b0011) ($or 1 1) is 1 (0b0001 OR 0b0001 = 0b0001)
( $not num ) ->
Returns zero if num is non-zero and
one if num is zero. Note that this is BOOLEAN NOT
and not BITWISE NOT. BITWISE NOT could be coded as
($minus ($minus 0 %1) 1)
for a two's complement
machine.
Example: ($not 0) is 1 ($not 1) is 0 ($not 5) is 0
( $yorn ) ->
Waits for the player to type a line of
input, returns one if this line begins with the
letter 'Y' or 'y', and returns zero otherwise. Note
that no prompt is automatically made for this input.
Example: ($say "Are you sure you want to quit? ") (IF ($yorn) THEN ($say "OK. Goodbye!\n") ($spec 3) ELSE ($say "Whew! That was a close one!\n") )
( $pct num ) ->
Returns one num percent of the time
and zero the rest of the time. This is equivalent
to ($ge num ($rand 100))
.
Example: (IF ($pct 30) THEN ($say "The troll swings at you, and hits!\n") ELSE ($say "The troll's axe misses you by a hair!\n") )
( $eq num1 num2 ) ->
Returns one if num1 is equal to
num2 and zero otherwise.
Example: ($setg loc ($loc .ME)) (IF ($eq @loc room1) THEN ($say "You are in room 1.\n") )
( $ne num1 num2 ) ->
Returns one if num1 is not
equal to num2 and zero otherwise.
Example: ($setg loc ($loc .ME)) (IF ($ne @LastLoc @loc) THEN ($say "You've moved since I last checked!\n") )
( $lt num1 num2 ) ->
Returns one if num1 is less
than num2 and zero otherwise.
Example: (IF ($lt @Score 100) THEN ($say "You are a novice adventurer\n") )
( $gt num1 num2 ) ->
Returns one if num1 is greater
than num2 and zero otherwise.
Example: (IF ($gt @Score 1000) THEN ($say "You are a super master grand ") ($say "champion mongo adventurer!!!\n") )
( $le num1 num2 ) ->
Returns one if num1 is less
than or equal to num2 and zero otherwise.
Example: (IF ($le @Score 1000) THEN ($say "You are a pretty good adventurer.\n") )
( $ge num1 num2 ) ->
Returns one if num1 is greater
than or equal to num2 and zero otherwise.
Example: (IF ($ge @Weight 200) THEN ($say "The ice breaks under your weight!\n") )
( $setg which val ) ->
Returns val. Sets the con-
tents of (or the value of) variable which to be val.
( $global which ) ->
Returns the contents of (or the
value of) variable which. Equivalent to @which,
with the exception that $global allows arithmetic
expressions.
Example: Given: VAR var[3]; (var + 0) = 10; (var + 1) = 20; (var + 2) = 30; The statement ($global ($plus var 2)) would return 30.
( $verb ) ->
Returns the current Verb. Equivalent
to @Verb.
Example: (IF ($eq ($verb) take) THEN ($say "You can't take that!!\n") )
( $dobj ) ->
Returns the current direct object.
Equivalent to @Dobj.
Example: (IF ($eq ($dobj) ball) THEN ($say "Dobj = ball\n") )
( $iobj ) ->
Returns the current indirect object.
Equivalent to @Iobj.
Example: (IF ($eq ($iobj) basket) THEN ($say "Iobj = basket\n") )
( $prep ) ->
Returns the current Preposition.
Equivalent to @Prep.
Example: (IF ($eq ($prep) into) THEN ($say "Prep = into\n") )
( $conj ) ->
Returns the current conjunction.
Equivalent to @Conj.
Example: (IF ($eq ($conj) 1) THEN ($say "The conjunction was 'but'\n") ELSE ($say "The conjunction was 'and' or ','\n") )
( $numd ) ->
Returns the length of the current
direct object list. Equivalent to @Numd.
Example: (IF ($gt ($numd) 1) THEN ($say "You may not use multiple direct objects!\n") )
ADL has an internal structure known as the Transition Vector. This structure is a list of ten verb IDs and is set and used by the following routines. These routines are typically used in the ACTION routines of rooms in scenarios in order to move the player around.
( $setv verb1 verb2 verb3 ... verb10 ) ->
No return
value. Initializes the Transition Vector to the
list of verbs verb1 verb2 verb3 ... verb10.
Example: ($setv north south east west ne se nw sw up down)
( $hit obj loc1 loc2 loc3 ... loc10 ) ->
No return
value. Scans the Transition Vector for a match with
the current Verb. If found, obj is moved to the
corresponding loc. Nothing happens if no match is
found. An attempt to move an object to location 0
(.ALL) is ignored.
Example: room1(ACTION) = ($hit .ME room2 room3 room4 0 0 0 0 0 0 0) ;
( $miss rout1 rout2 rout3 ... rout10 ) ->
No return
value. Scans the Transition Vector for a match with
the current Verb. If found, the corresponding rout
is called. Nothing happens if no match is found.
An attempt to call routine 0 does nothing.
Example: cg = ($say "You can't go that way.\n") room2(ACTION) = ($miss 0 0 0 cg cg cg cg cg cg cg) ;
There are basically three types of strings which an ADL program uses. The first type of string is the compile-time string (a string which was present in the ADL source file of the scenario). All compile-time strings have a positive string ID and exist for the duration of program execution.
The second type of string is the "volatile" run-time string. Examples of this type of string include strings typed by the player and strings produced by the builtin routines $subs, $cat, $read, $name, $vname, $mname, $pname, $num, and $chr (see also Sections 7.8 and 7.9). Volatile strings have negative string IDs and are "flushed" at the beginning of each turn (just before the Daemon phase).
The third type of string is the "non-volatile" run-time string. These strings also have negative string IDs but they are never "flushed". These strings are produced by the $savestr routine. Note that there is no easy way to distinguish volatile and non-volatile run-time strings.
In the context of the $subs and $pos routines, strings are indexed starting at zero (the first character of the string). The following routines operate on all types of strings:
( $eqst str1 str2 ) ->
Returns one if str1 has the
same contents as str2 and zero otherwise. Note that
this is NOT the same as ($eq str1 str2), since the
$eq only compares the string IDs of the strings.
Example: The program: ($setg str1 "hello") ($setg str2 ($cat "he" "llo")) (IF ($eqst @str1 @str2) THEN ($say "String 1 == string 2\n") ) (IF ($ne @str1 @str2) THEN ($say "String ID 1 != string ID 2\n") ) will produce the output: String 1 == string 2 String ID 1 != string ID 2
( $subs str start len ) ->
Returns a volatile copy
of the substring of str starting at start and going
for len characters. If len is 0, the suffix of str
starting at start is returned.
Example: The program: ($setg str "Hello world") ($say ($subs @str 0 5) "\n") ($say ($subs @str 6 0) "\n") will produce the output: Hello world
( $leng str ) ->
Returns the length of str.
Example: ($leng "Hello") is 5 ($leng "") is 0
( $cat str1 str2 ) ->
Returns a volatile string
which is the result of concatenating str1 and str2.
Example: ($cat "hello " "world") returns "hello world"
( $pos str1 str2 ) ->
Returns the position of str1
in str2. If no occurrence of str1 is found in str2,
-1 is returned.
Example: ($pos "hello" "hello world") is 0 ($pos "Foobar" "bletch") is -1 ($pos "testing" "This is a test") is -1 ($pos "is" "This is a test") is 2
( $read ) ->
Returns a volatile string which is read
from the player's keyboard. Note that no prompt is
automatically generated.
Example: ($say "What is your name? ") ($setg MyName ($read)) ($say "Hello, " @MyName ", welcome to ADL!\n")
->
Returns a non-volatile copy of
str. Note that str may be any string -- compile-
time, volatile, or non-volatile.
Example: ($setg MyName ($savestr @MyName))
The following routines all return volatile strings which contain the requested name.
( $name obj ) ->
Returns a volatile string contain-
ing the (possibly multiple-word) name of obj.
Example: ($say "You see no " ($name @Dobj) " here!\n")
( $vname verb ) ->
Returns a volatile string con-
taining the name of verb.
Example: ($say "No multiple objects with " ($vname @Verb) "!\n")
( $mname modif ) ->
Returns a volatile string con-
taining: the name of modifier modif (if modif is
greater than zero), the name of verb -modif (if
modif is less than zero), or the null string (if
modif is zero).
Example: ($say "The modifier of blue ball is " ($mname blue) "\n")
( $pname prep ) ->
Returns a volatile string con-
taining the name of Preposition prep.
Example: ($say "The sentence is:\n") ($say ($vname @Verb) " " ($name @Dobj) " " ($pname @Prep) " " ($name @Iobj) )
The following routines perform conversions between strings and numbers.
( $str num ) ->
Returns a volatile string which con-
tains the ASCII representation of num.
Example: ($str 3) is the string "3"
( $num str ) ->
Returns the numeric value of str.
Example: ($num "234") is the number 234
( $ord str ) ->
Returns the ASCII code of the first
character in str.
Example: ($ord "ABC") is 65
( $chr num ) ->
Returns a volatile string which con-
tains exactly one character, whose ASCII code is
num.
Example: ($chr 97) is the string "a".
The following routines are the means whereby the ADL programmer may modify the Internal Structures described in Chapter 3. See also Chapter 4 for the use of some of these routines.
( $sdem rout ) ->
No return value. Activates rout
as a daemon.
Example: ($sdem Looker) ($sdem Follower)
( $ddem rout ) ->
No return value. De-activates
rout as a daemon. No action is taken if rout is not
an active daemon.
Example: ($ddem Follower)
( $sfus actor rout count ) ->
No return value.
Activates rout as a fuse associated with actor to be
executed in count turns.
Example: ($sfus .ME LampDie 300)
( $dfus actor rout ) ->
No return value. De-
activates rout as a fuse associated with actor. No
action is taken if rout is not an active fuse.
Example: (IF @BatteryFound THEN ($dfus .ME LampDie) )
->
No return value. Increments the turn counter by nturns (or 1 if nturns is
not given) and activates any fuses associated with
the current actor that have "burned down". The
"burned down" fuses are then de-activated. The ADL
programmer to "halt time" by refraining from incrementing the turn counter. Usually, ($incturn) is
only called when the daemons are executing for the
primary actor. For other actors, ($incturn 0) is
used to see whether the fuses associated with the
current actor have burned down, without incrementing
the turn counter.
Example: sleep(ACTION) = ($incturn 300) ;
( $turns ) ->
Returns the current value of the turn
counter.
Example: (IF ($eq @Verb north) THEN (IF ($gt ($turns) 230) THEN ($move .ME room3) ELSE ($move .ME room5) ) )
( $prompt rout ) ->
No return value. Sets the
prompter to be rout.
Example: ($prompt Prompter)
( $actor obj str flag ) ->
No return value.
Activates obj as a new Actor with the line buffer
initialized to str. If flag is non-zero then the
new Actor will be interactive. If flag is zero then
the new Actor will be non-interactive. If str is
zero then the line buffer will be initialized to the
empty string.
Example: ($actor Myself NULL TRUE) ($setg s "Go east then south. Push button. Go north") ($actor robot @s FALSE)
( $delact obj ) ->
No return value. Deletes the
Actor associated with obj from the Actor list. No
action is performed if obj is not an active Actor.
Example: (IF ($prop robot BROKEN) THEN ($delact robot) )
( $define str1 str2 ) ->
No return value. Informs
the parser that upon input from an Actor, the string
str1 is to be replaced with the contents of str2.
This process continues until an infinite loop is
detected or until a word is found for which there is
no corresponding expansion. Str1 must contain no
spaces. Str2 may contain several words separated by
spaces. Note that in the case of multiple definitions (such as ($define "a" "b") followed by
($define "a" "c")), the macro table should be viewed
as a stack with $define pushing macro definitions on
the stack and $undef popping definitions.
Example: (IF ($eq @MyDir 1) THEN ($define "left" "north") ($define "right" "south") ELSE ($define "left" "south") ($define "right" "north") )
( $undef str ) ->
No return value. This routine
removes str and its expansion from the macro table.
No action is performed if str is not an active
macro.
Example: ($undef "left") ($undef "right")
( $spec code arg1 arg2 ... argN ) ->
No return
value. Performs a special, system-dependent operation. Note that not all operations exist in all
implementations. Consult your local ADL documentation for information.
+------+---------------------------------------+ | code | function | +------+---------------------------------------+ | 1 | Toggle the instruction trace flag | | 2 | Restart this game | | 3 | Terminate execution of this game | | 4 | Save this game in file arg1 | | 5 | Restore this game from file arg1 | | 6 | Execute the system program named arg1 | | 7 | Preserve unknown words in file arg1 | | 8 | Write a script to file arg1 | | 9 | Print a header line on the screen | | 10 | Set the right margin | +------+---------------------------------------+
Examples: VERB debug; debug(ACTION) = ($spec 1); VERB restart; restart(ACTION) = ($spec 2); VERB quit; quit(ACTION) = ($spec 3); VERB save; save(ACTION) = LOCAL name; ($say "Save to what filename? ") ($setg name ($read)) (IF ($leng @name) THEN ($spec 4 @name) ) ; VERB restore; restore(ACTION) = LOCAL name; ($say "Restore from what filename? ") ($setg name ($read)) (IF ($leng @name) THEN ($spec 5 @name) ) ; VERB shell; shell(ACTION) = ($spec 6 "/bin/csh") ; VERB savewords; savewords(ACTION) = ($spec 7 "unknown.wrds") ; VERB script; script(ACTION) = LOCAL name; ($say "Script to what filename? ") ($setg name ($read)) (IF ($leng @name) THEN ($spec 8 @name) ) ; Status = ($spec 9 ($name ($loc .ME)) @Score ($turns)) ; START = ($spec 10 60); { It makes the text prettier }
These routines are placed here for lack of a better place to put them.
( $say str1 str2 ... ) ->
No return value. Prints
the messages str1 str2 ... on the screen. Note that
ADL automatically "word-wraps" strings so that they
fit within the right margin as closely as possible.
Therefore, it is not necessary for the ADL programmer to take great care in formatting the messages
passed to $say. If the programmer desires that the
current line be terminated, and output start on a
new line, the character sequence "\n" should be
embedded in the string. Note that each str may
actually be an expression such as ($name foo) or
($num @Score).
Example: ($say "Hi! My name is " @MyName "! How are you today?\n") Note that MyName is assumed to contain a string ID.
( $arg num ) ->
Returns the numth argument of the
current routine. It is basically the same as %num
except that in this case num may be a numeric
expression, not just a numeric constant. ($arg 0)
returns the number of arguments passed to this invo-
cation of the current routine.
Example: { Print all of the arguments to this routine } ($setg i 1) (WHILE ($le @i %0) DO ($say "Arg " @i " = " ($arg @i) "\n") )
( $exit code ) ->
Doesn't return to the current routine. $exit terminates execution of the current
phase. If code is 0, control passes to the next
phase. If code is 1, control passes to the outer-
most loop. If code is 2, control passes to the top
of the Dobj loop. If code is 3, control passes to
the parser which attempts to complete a partial sentence. See the diagram in Chapter 4 for a complete
definition.
Example: take(PREACT) = (IF ($ne ($loc @Dobj) ($loc .ME)) THEN ($say "You don't see that here!\n") { Skip the rest of the phases } ($exit 1) ) ; safe(ACTION) = (IF ($eq @Verb take) THEN ($say "You can't budge the safe.\n") { Go on to the rest of the Dobjs } ($exit 2) ) ; ball(ACTION) = (IF ($prop ball BROKEN) THEN { Rely on the default verb ACTION } ($exit 0) ) ($say "The ball bounces nicely.\n") ; NOVERB(PREACT) = ($say "What do you want me to do with the " ($say ($name @Dobj) "?\n") { Re-parse the sentence } ($exit 3) ;
( $return expr ) ->
Doesn't return to the current
routine. Evaluates expr and returns the result to
the current routine's caller. Note that in the
absence of an explicit $return, the return value of
a routine is the same as the value of the last
statement executed.
Example: Increment = ($return ($plus %1 1)) ($say "Increment( 3 ) = " (Increment 3) "\n") Increment( 3 ) = 4
( $val expr ) ->
Evaluates expr and returns the
result. Expr may be a routine call, a constant, a
string, or anything that yields a 16-bit value.
This routine is most useful in conditional expressions.
Example: Signum = (IF ($lt %1 0) THEN ($val -1) ELSEIF ($eq %1 0) THEN ($val 0) ELSE ($val 1) ) ;
( $phase ) ->
Returns the number of the phase
currently executing. This number is 0 during the
START phase, 1 during the Daemon phase, 2 during the
Actor ACTION, 3 during the Verb PREACT, 4 during the
Iobj ACTION, 5 during the Dobj ACTION, 6 during the
Verb ACTION, and 7 during the Room ACTION.
Example: (IF ($eq ($phase) 2) THEN ($say "This is the Actor ACTION\n") ELSEIF ($eq ($phase) 4) THEN ($say "This is the Iobj ACTION\n") ELSEIF ($eq ($phase) 5) THEN ($say "This is the Dobj ACTION\n") )