Difference between revisions of "Manual:DIL Manual/command()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
 
(XML import)
 
Line 1: Line 1:
 +
<span id="bfcomm"></span>
 +
integer command ( cmd : string or integer )
 +
    cmd : A string of the full typed command, e.g. "push" or "say".
 +
          Alternatively you can specify one of the macros defined in
 +
          values.h and/or vme.h, e.g. CMD_SAY
 +
  return: Whether the command specified by the activator is the one of
 +
          the argument.
 +
 +
It is noteworthy, that unlike simple compares like this;
  
 +
if ("spook" in cmdstr)
 +
or
 +
if (cmdstr == "spook")
 +
where the first will activate even if the cmdstr is "nospook", and the
 +
second only if cmdstr equals the word "spook" to the letter, the
 +
following construct will activate as long as the contents
 +
of cmdstr doesn't conflict with cmd;
  
 +
if (command("spook"))
 +
ie, it will receive the same kind of treatment as a 'regular' command.
 +
That means that you provide ease of use to the user (allowing shorthand
 +
notation), while securing that you're doing what the user wants.
 +
<STRONG>CAVEAT</STRONG> Builder:
 +
If you use a string argument as cmd, be sure that
 +
there are no white-space in it, ie, that the argument does only
 +
consist of letters.
 +
 +
Example:
 +
    command("spook");
 +
 +
    is a valid string, while this construct;
 +
 +
    command("spook him");
 +
 +
    is NOT valid. The reason of that is that cmdstr only contains the
 +
    FIRST word of the input from the player, and thus the latter
 +
    construct could never evaluate to true. This should be evident
 +
    taking the above information into account, as "spook him" could
 +
    never equal "spook" (which would indeed be the text in cmdstr
 +
    if the player entered the string "spook him".)
 
<span id="bfcomm"></span>
 
<span id="bfcomm"></span>
 
  integer command ( cmd : string or integer )
 
  integer command ( cmd : string or integer )
Line 11: Line 49:
 
  It is noteworthy, that unlike simple compares like this;
 
  It is noteworthy, that unlike simple compares like this;
  
  if ("spook" in cmdstr) {
+
  if ("spook" in cmdstr)
...
+
or
...
+
  if (cmdstr == "spook")
}
+
where the first will activate even if the cmdstr is "nospook", and the
or
 
  if (cmdstr == "spook") {
 
...
 
...
 
}
 
 
 
where the first will activate even if the cmdstr is "nospook", and the
 
 
  second only if cmdstr equals the word "spook" to the letter, the
 
  second only if cmdstr equals the word "spook" to the letter, the
 
  following construct will activate as long as the contents
 
  following construct will activate as long as the contents
 
  of cmdstr doesn't conflict with cmd;
 
  of cmdstr doesn't conflict with cmd;
  
  if (command("spook")) {
+
  if (command("spook"))
...
+
ie, it will receive the same kind of treatment as a 'regular' command.
...
 
}
 
 
 
ie, it will receive the same kind of treatment as a 'regular' command.
 
 
  That means that you provide ease of use to the user (allowing shorthand
 
  That means that you provide ease of use to the user (allowing shorthand
 
  notation), while securing that you're doing what the user wants.
 
  notation), while securing that you're doing what the user wants.

Latest revision as of 22:33, 4 December 2025

integer command ( cmd : string or integer )
   cmd : A string of the full typed command, e.g. "push" or "say".
         Alternatively you can specify one of the macros defined in
         values.h and/or vme.h, e.g. CMD_SAY
 return: Whether the command specified by the activator is the one of
         the argument.
It is noteworthy, that unlike simple compares like this;
	if ("spook" in cmdstr)

or

	if (cmdstr == "spook")

where the first will activate even if the cmdstr is "nospook", and the

second only if cmdstr equals the word "spook" to the letter, the
following construct will activate as long as the contents
of cmdstr doesn't conflict with cmd;
	if (command("spook"))

ie, it will receive the same kind of treatment as a 'regular' command.

That means that you provide ease of use to the user (allowing shorthand
notation), while securing that you're doing what the user wants.
CAVEAT Builder:
If you use a string argument as cmd, be sure that
there are no white-space in it, ie, that the argument does only
consist of letters.
Example:
    command("spook");
    is a valid string, while this construct;
    command("spook him");
    is NOT valid. The reason of that is that cmdstr only contains the
    FIRST word of the input from the player, and thus the latter
    construct could never evaluate to true. This should be evident
    taking the above information into account, as "spook him" could
    never equal "spook" (which would indeed be the text in cmdstr
    if the player entered the string "spook him".)

integer command ( cmd : string or integer )
   cmd : A string of the full typed command, e.g. "push" or "say".
         Alternatively you can specify one of the macros defined in
         values.h and/or vme.h, e.g. CMD_SAY
 return: Whether the command specified by the activator is the one of
         the argument.
It is noteworthy, that unlike simple compares like this;
	if ("spook" in cmdstr)

or

	if (cmdstr == "spook")

where the first will activate even if the cmdstr is "nospook", and the

second only if cmdstr equals the word "spook" to the letter, the
following construct will activate as long as the contents
of cmdstr doesn't conflict with cmd;
	if (command("spook"))

ie, it will receive the same kind of treatment as a 'regular' command.

That means that you provide ease of use to the user (allowing shorthand
notation), while securing that you're doing what the user wants.
CAVEAT Builder:
If you use a string argument as cmd, be sure that
there are no white-space in it, ie, that the argument does only
consist of letters.
Example:
    command("spook");
    is a valid string, while this construct;
    command("spook him");
    is NOT valid. The reason of that is that cmdstr only contains the
    FIRST word of the input from the player, and thus the latter
    construct could never evaluate to true. This should be evident
    taking the above information into account, as "spook him" could
    never equal "spook" (which would indeed be the text in cmdstr
    if the player entered the string "spook him".)