Difference between revisions of "Manual:DIL Manual/command()"
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = command() = | |
| − | + | '''Function''' (integer). Tells whether the event that woke the program is a given command. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | command(name : string) | |
| + | command(no : integer) | ||
| − | + | Right after a <code>wait()</code>, <code>command()</code> 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: <code>command("say")</code> is true for "say hello" and for any abbreviation the game takes as <code>say</code>. With an integer it compares the event's command number with one of the <code>CMD_AUTO_*</code> 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 <code>wait()</code>: <code>wait(SFB_CMD, command("pull"))</code>. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | name || string || One command word, in lower case, such as <code>"say"</code> or <code>"pull"</code>. | ||
| + | |- | ||
| + | | no || integer || A <code>CMD_AUTO_*</code> constant from <code>vme/include/vme.h</code>. | ||
| + | |} | ||
| − | + | == 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 <code>commands.def</code>): 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 <code>command("say")</code> is safer than <code>cmdstr == "say"</code> or <code>"say" in cmdstr</code> (which is also true for "essay"). | ||
| + | * '''A word the game doesn't know''' (<code>"pull"</code>, <code>"ring"</code>): 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. <code>command("Say")</code> never matches. | ||
| + | * Give one word. <code>cmdstr</code> holds the command word and <code>argument</code> the rest of the line. | ||
| + | * The integer form: <code>CMD_AUTO_TICK</code> (heartbeat), <code>CMD_AUTO_COMBAT</code> (combat round), <code>CMD_AUTO_DAMAGE</code>, <code>CMD_AUTO_DEATH</code>, <code>CMD_AUTO_MSG</code> (a message from <code>sendto()</code>, <code>sendtoall()</code> or <code>sendtoalldil()</code>), <code>CMD_AUTO_ENTER</code>, <code>CMD_AUTO_EXTRACT</code>, <code>CMD_AUTO_PLAY</code>, <code>CMD_AUTO_LEAVE</code>, <code>CMD_AUTO_SAVE</code>, <code>CMD_AUTO_EDIT</code> and <code>CMD_AUTO_UNKNOWN</code> (a word that isn't a command), all in <code>vme.h</code>. Every command from <code>commands.def</code> has the number 0 (<code>CMD_AUTO_NONE</code>). There are no constants such as <code>CMD_SAY</code>. | ||
| + | * Like <code>activator</code> and <code>argument</code>, it describes the latest event only. After a <code>pause</code> or another <code>wait</code> it describes that one. | ||
| + | * <code>command</code> is a reserved word, so it can't be a variable name. | ||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | 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 | ||
| + | </pre> | ||
| + | A bell that sways every 30 seconds and that players can ring; <code>block</code> stops the game from answering "ring is not a known command". | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/wait()|wait()]] | |
| − | + | * [[Manual:DIL Manual/cmdstr|cmdstr]] | |
| − | + | * [[Manual:DIL Manual/argument|argument]] | |
| − | + | * [[Manual:DIL Manual/activator|activator]] | |
| − | + | * [[Manual:DIL Manual/block|block]] | |
| − | + | * [[Manual:DIL Manual/chead()|chead()]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 23:15, 14 November 2026
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".