Manual:DIL Manual/command()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:15, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

command()

Function (integer). Tells whether the event that woke the program is a given command.

command(name : string)
command(no : integer)

Right after a wait(), command() tells what woke the program up. With a string it is TRUE when the character typed that command, the way the game itself understands commands: command("say") is true for "say hello" and for any abbreviation the game takes as say. With an integer it compares the event's command number with one of the CMD_AUTO_* constants, for events that aren't typed: a heartbeat tick, a combat round, a death, and so on.

It is mostly used in the condition of wait(): wait(SFB_CMD, command("pull")).

Parameters

Name Type Meaning
name string One command word, in lower case, such as "say" or "pull".
no integer A CMD_AUTO_* constant from vme/include/vme.h.

Returns

Integer: 1 if the event is that command, otherwise 0. It fails if the argument fails.

Notes

  • A command the game knows (one in commands.def): the string is looked up like a typed word, and the command it stands for is compared with the command the character typed. So it doesn't matter how the character abbreviated it, and command("say") is safer than cmdstr == "say" or "say" in cmdstr (which is also true for "essay").
  • A word the game doesn't know ("pull", "ring"): it matches when the character typed that word or the start of it ("pul"), as long as what was typed isn't itself taken as a real command (a short start such as "pu" usually is).
  • The lookup of a known command is case sensitive: write the name in lower case. command("Say") never matches.
  • Give one word. cmdstr holds the command word and argument the rest of the line.
  • The integer form: CMD_AUTO_TICK (heartbeat), CMD_AUTO_COMBAT (combat round), CMD_AUTO_DAMAGE, CMD_AUTO_DEATH, CMD_AUTO_MSG (a message from sendto(), sendtoall() or sendtoalldil()), CMD_AUTO_ENTER, CMD_AUTO_EXTRACT, CMD_AUTO_PLAY, CMD_AUTO_LEAVE, CMD_AUTO_SAVE, CMD_AUTO_EDIT and CMD_AUTO_UNKNOWN (a word that isn't a command), all in vme.h. Every command from commands.def has the number 0 (CMD_AUTO_NONE). There are no constants such as CMD_SAY.
  • Like activator and argument, it describes the latest event only. After a pause or another wait it describes that one.
  • command is a reserved word, so it can't be a variable name.

Example

dilbegin bell_ringer();
code
{
   heartbeat := PULSE_SEC * 30;
:start:
   wait(SFB_CMD | SFB_TICK, command(CMD_AUTO_TICK) or command("ring"));
   if (command(CMD_AUTO_TICK))
   {
      act("The bell sways in the wind.", A_ALWAYS, self, null, null, TO_ROOM);
      goto start;
   }
   if (activator.type != UNIT_ST_PC)
      goto start;
   block;
   act("$1n rings the bell. DONG!", A_ALWAYS, activator, null, null, TO_ROOM);
   goto start;
}
dilend

A bell that sways every 30 seconds and that players can ring; block stops the game from answering "ring is not a known command".

See also