Manual:DIL Manual/command()
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, andcommand("say")is safer thancmdstr == "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.
cmdstrholds the command word andargumentthe 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 fromsendto(),sendtoall()orsendtoalldil()),CMD_AUTO_ENTER,CMD_AUTO_EXTRACT,CMD_AUTO_PLAY,CMD_AUTO_LEAVE,CMD_AUTO_SAVE,CMD_AUTO_EDITandCMD_AUTO_UNKNOWN(a word that isn't a command), all invme.h. Every command fromcommands.defhas the number 0 (CMD_AUTO_NONE). There are no constants such asCMD_SAY. - Like
activatorandargument, it describes the latest event only. After apauseor anotherwaitit describes that one. commandis 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".