Difference between revisions of "Manual:DIL Manual/excmdstr"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = excmdstr = | |
| − | + | '''Variable''' (string, read-only). | |
| − | |||
| − | |||
| − | + | excmdstr : string | |
| − | + | 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. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | < | ||
| − | |||
| − | |||
| − | |||
| − | + | 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 <code>if (excmdstr != "quit")</code>. | |
| − | + | * 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>. | |
| − | + | * <code>excmdstr + " " + argument</code> 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 == | ||
| + | <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
Contents
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)afterwait(SFB_CMD, ...). excmdstr + " " + argumentis 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.