Difference between revisions of "Manual:DIL Manual/cmdstr"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = cmdstr = | |
| − | + | '''Variable''' (string, read-only). | |
| − | |||
| − | |||
| − | + | cmdstr : string | |
| − | + | The full name of the command in the event that woke the program, as commands.def names it, even when the player typed an abbreviation: <code>n</code> gives <code>"north"</code>, <code>'hi</code> gives <code>"say"</code>. For a word that is no command, it's that word in lower case. | |
| − | |||
| − | |||
| − | < | ||
| − | |||
| − | |||
| − | |||
| − | + | It is set in SFB_CMD events and in the SFB_DONE and SFB_PRE events of a command (after a <code>give</code>, <code>"give"</code>), and the first time a player command written in DIL runs. For ticks, messages, damage and other events that aren't a named command it is null, and comparing it with a string gives false. | |
| − | + | == Notes == | |
| − | + | * <code>cmdstr + " " + argument</code> is not what the player typed: the abbreviation is expanded and the spaces are trimmed. excmdstr is the word as typed. | |
| − | + | * To test for a command, use command(). cmdstr is for when the name is needed as text, for instance to repeat the command: basemove.zon's follow does <code>c := cmdstr;</code> and later <code>exec(c, self);</code>. | |
| + | * It belongs to the current event; copy it into a variable before a wait or pause. | ||
| + | * It can't be assigned. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin fnpri(FN_PRI_BLOCK) gate_guard(); | ||
| + | code | ||
| + | { | ||
| + | :start: | ||
| + | wait(SFB_CMD, (command("north") or command("up")) and | ||
| + | (activator.type == UNIT_ST_PC)); | ||
| + | if (self.position < POSITION_STANDING) | ||
| + | goto start; | ||
| + | block; | ||
| + | act("$1n stops you from going $2t.", A_SOMEONE, self, cmdstr, activator, TO_VICT); | ||
| + | act("$1n stops $3n from going $2t.", A_SOMEONE, self, cmdstr, activator, TO_NOTVICT); | ||
| + | goto start; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | A guard that blocks players going north or up, and names the direction in full whatever they typed. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/excmdstr|excmdstr]] | ||
| + | * [[Manual:DIL Manual/excmdstr case|excmdstr case]] | ||
| + | * [[Manual:DIL Manual/argument|argument]] | ||
| + | * [[Manual:DIL Manual/command()|command()]] | ||
| + | * [[Manual:DIL Manual/SFB CMD|SFB CMD]] | ||
Latest revision as of 23:19, 14 November 2026
Contents
cmdstr
Variable (string, read-only).
cmdstr : string
The full name of the command in the event that woke the program, as commands.def names it, even when the player typed an abbreviation: n gives "north", 'hi gives "say". For a word that is no command, it's that word in lower case.
It is set in SFB_CMD events and in the SFB_DONE and SFB_PRE events of a command (after a give, "give"), and the first time a player command written in DIL runs. For ticks, messages, damage and other events that aren't a named command it is null, and comparing it with a string gives false.
Notes
cmdstr + " " + argumentis not what the player typed: the abbreviation is expanded and the spaces are trimmed. excmdstr is the word as typed.- To test for a command, use command(). cmdstr is for when the name is needed as text, for instance to repeat the command: basemove.zon's follow does
c := cmdstr;and laterexec(c, self);. - It belongs to the current event; copy it into a variable before a wait or pause.
- It can't be assigned.
Example
dilbegin fnpri(FN_PRI_BLOCK) gate_guard();
code
{
:start:
wait(SFB_CMD, (command("north") or command("up")) and
(activator.type == UNIT_ST_PC));
if (self.position < POSITION_STANDING)
goto start;
block;
act("$1n stops you from going $2t.", A_SOMEONE, self, cmdstr, activator, TO_VICT);
act("$1n stops $3n from going $2t.", A_SOMEONE, self, cmdstr, activator, TO_NOTVICT);
goto start;
}
dilend
A guard that blocks players going north or up, and names the direction in full whatever they typed.