Clue
Command System Summary

There are really two parts to understanding the command system. The first is understanding the process of creating a command, and the second is just how commands are used and applied during the game. Much of the discussion here will revolve around the code found in command-system.

Anatomy of a Command

Commands are always added using the add-command or add-player-command functions. Each of these takes a specification, a description, and a function. Check the engine interface for those details.

Specification

The specification is what is matched against the player's input.  If the specification agrees with the input, then the function in the command is executed, otherwise the command is skipped and we try to match the input with another command. You should note that only one command can be executed, even if several command specifications match the input. There are a total of four forms that a command specification can take. When matching the input, it first tries matching the raw input string against these forms:

If neither of the above forms are used for the specification, the input is converted to a list and matched against the following:

A combined approach to writing a spec list would be:

Some examples of specifications are:

Help Description

This is simply a string that carries information that might be useful to display to the player. It is displayed whenever the player types help, or depending on the context when the player looks at an object. An example of a few help strings would be:

Note, if the description string is just "", it is considered a hidden command because the player has no information about the command. Of course, the command can always be documented somewhere else, or the player can just try to guess.

Function

When a successful match is made with the spec, this function is applied to the player object and the input. Thus the function should probably begin with something like (lambda (plyr input) ...). Note that the input passed to this function will be in the same form as what matched the specification. So, if the specification was a string, a string will be passed as the input, and likewise with a list.

The function should do some type of effect depending on the command. For instance, a go command should call transfer. There's really no restriction at what the command can do - it can check the location and contents of the player, or anything else necessary. In the end, this function should return one of the following:

Command System Process

Notice that every object in the game can carry a set of commands. This allows for contextual commands that show up only when the player is in or around the object holding the command. Looking at the code for commands in players, you'll note the hierarchy of commands for players. Commands have the following precedence:

So you could override a command by placing one with the same specs in anything with a higher precedence. You run the risk of seeing that command twice when typing help. You won't be overriding commands this way for the problem set, but you may find it handy if you try the contest.

Note that after completing the problem set, you will have a much more flexible way of assigning priority to commands!




CS212 Home Page
© 2000 Cornell University Computer Science
Prepared by Brandon Bray