Difference between revisions of "Manual:DIL Manual/excmdstr"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="excmdstr"></span>
+
= excmdstr =
−
'excmdstr'
+
'''Variable''' (string, read-only).
−
    This variable is a string which contains the "first string" which was entered
 
−
    by a player. The result of adding:
 
  
−
      excmdstr + " " + argument
+
excmdstr : string
  
−
    is the entire string as entered by the player. The 'excmdstr' is not
+
The first word of the line the player typed, in lower case, not expanded: <code>N</code> gives <code>"n"</code>, where cmdstr gives <code>"north"</code>. A line starting with <code>'</code> gives <code>"say"</code>, one starting with <code>,</code> gives <code>"emote"</code>. A word that is no command is there too.
−
    EXPANDED by the interpreter, but it is converted to lower case. So
 
−
    assume a player types 'S' then the string is returned as 's'.  The
 
−
    'excmdstr' is however changed to all lower case if you don't want
 
−
    this see 'excmdstr_case'.
 
−
<span id="excmdstr"></span>
 
−
'excmdstr'
 
−
    This variable is a string which contains the "first string" which was entered
 
−
    by a player. The result of adding:
 
  
−
      excmdstr + " " + argument
+
It is set while a typed command is being handled: in SFB_CMD events, in the SFB_DONE and SFB_PRE events of that command, and the first time a player command written in DIL runs. Otherwise (ticks, messages, after the command) it is null.
  
−
    is the entire string as entered by the player. The 'excmdstr' is not
+
== Notes ==
−
    EXPANDED by the interpreter, but it is converted to lower case. So
+
* Use it to insist on the full word: commands.zon's quit refuses with <code>if (excmdstr != "quit")</code>.
−
    assume a player types 'S' then the string is returned as 's'. The
+
* It reads typed input that isn't a command: competition.zon's menu takes a number with <code>atoi(excmdstr)</code> after <code>wait(SFB_CMD, ...)</code>.
−
    'excmdstr' is however changed to all lower case if you don't want
+
* <code>excmdstr + " " + argument</code> is the line as typed, apart from case and spacing. excmdstr_case keeps the case.
−
    this see 'excmdstr_case'.
+
* It belongs to the command, not to the event: if the program exec()s the same command while handling it, excmdstr is null afterwards. Copy it into a variable first.
 +
* It can't be assigned.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin do_retire(arg : string);
 +
code
 +
{
 +
  if (excmdstr != "retire")
 +
  {
 +
      sendtext("You typed '" + excmdstr + "'. Type 'retire', no less, to retire.<br/>", self);
 +
      quit;
 +
  }
 +
  sendtext("You retire from adventuring.<br/>", self);
 +
  quit;
 +
}
 +
dilend
 +
</pre>
 +
A player command (<code>func = do_retire@zone</code> in commands.def) that only works when typed in full, as quit in commands.zon.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/excmdstr case|excmdstr case]]
 +
* [[Manual:DIL Manual/cmdstr|cmdstr]]
 +
* [[Manual:DIL Manual/argument|argument]]
 +
* [[Manual:DIL Manual/command()|command()]]

Latest revision as of 23:19, 14 November 2026

excmdstr

Variable (string, read-only).

excmdstr : string

The first word of the line the player typed, in lower case, not expanded: N gives "n", where cmdstr gives "north". A line starting with ' gives "say", one starting with , gives "emote". A word that is no command is there too.

It is set while a typed command is being handled: in SFB_CMD events, in the SFB_DONE and SFB_PRE events of that command, and the first time a player command written in DIL runs. Otherwise (ticks, messages, after the command) it is null.

Notes

  • Use it to insist on the full word: commands.zon's quit refuses with if (excmdstr != "quit").
  • It reads typed input that isn't a command: competition.zon's menu takes a number with atoi(excmdstr) after wait(SFB_CMD, ...).
  • excmdstr + " " + argument is the line as typed, apart from case and spacing. excmdstr_case keeps the case.
  • It belongs to the command, not to the event: if the program exec()s the same command while handling it, excmdstr is null afterwards. Copy it into a variable first.
  • It can't be assigned.

Example

dilbegin do_retire(arg : string);
code
{
   if (excmdstr != "retire")
   {
      sendtext("You typed '" + excmdstr + "'. Type 'retire', no less, to retire.<br/>", self);
      quit;
   }
   sendtext("You retire from adventuring.<br/>", self);
   quit;
}
dilend

A player command (func = do_retire@zone in commands.def) that only works when typed in full, as quit in commands.zon.

See also