Difference between revisions of "Manual:DIL Manual/exec()"
Jump to navigation
Jump to search
(XML import) |
(corrected from the DIL keyword tests (T029-T043)) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | = exec() = | |
| − | + | '''Procedure.''' Makes a character carry out a command, as if they had typed it. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | exec(cmd : string, ch : unitptr) | |
| − | |||
| − | exec ( | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | <code>ch</code>, a player or an NPC, carries out <code>cmd</code> at once through the ordinary command interpreter: the same checks (position, doors, ...), the same messages, and the same events for the programs around. Nothing tells whether it worked; check afterwards, for example <code>self.outside</code> after a move. | |
| + | |||
| + | == Parameters == | ||
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | cmd || string || The command and its arguments, e.g. <code>"say Hello"</code> or <code>"get key"</code>. | ||
| + | |- | ||
| + | | ch || unitptr || The character who does it. | ||
| + | |} | ||
| + | |||
| + | == Notes == | ||
| + | * A move made with exec() is followed by a <code>look</code> in the new room, and programs that see the character's commands (<code>aware</code> ones on the character itself, too) see that look as a command. | ||
| + | * <code>ch</code> must be a character: on an object, a room or null nothing happens. | ||
| + | * This is the way to move an NPC through an exit: <code>exec("north", self)</code> makes an ordinary move, with position checks, leave and arrive messages and every program that listens for movement. Use <code>link()</code> only where there is no exit. | ||
| + | * The program that calls <code>exec</code> doesn't get the command itself (it is busy running), but the other programs on <code>ch</code> and around it do, as <code>SFB_CMD</code>, and as <code>SFB_DONE</code> when the command succeeds. | ||
| + | * Commands are at most 512 characters; a longer one is cut there and logged. | ||
| + | * A god (level 200 or more) can't be made to use a command that only gods have: it is refused and logged. | ||
| + | * If the command destroys <code>ch</code> or takes it away, and the program has <code>secure</code>d <code>ch</code>, the secure fires. | ||
| + | * On a player it looks to them as if they typed it; use it on players with care. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin go_east(); | ||
| + | var | ||
| + | here : unitptr; | ||
| + | code | ||
| + | { | ||
| + | here := self.outside; | ||
| + | exec("east", self); | ||
| + | if (self.outside == here) | ||
| + | exec("say I can't get through here.", self); | ||
| + | return; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Walks an NPC east and checks that it got there. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/link()|link()]] | ||
| + | * [[Manual:DIL Manual/command()|command()]] | ||
| + | * [[Manual:DIL Manual/send done()|send done()]] | ||
| + | * [[Manual:DIL Manual/outside|outside]] | ||
| + | * [[Manual:DIL Manual/SFB CMD|SFB_CMD]] | ||
Latest revision as of 07:20, 15 November 2026
exec()
Procedure. Makes a character carry out a command, as if they had typed it.
exec(cmd : string, ch : unitptr)
ch, a player or an NPC, carries out cmd at once through the ordinary command interpreter: the same checks (position, doors, ...), the same messages, and the same events for the programs around. Nothing tells whether it worked; check afterwards, for example self.outside after a move.
Parameters
| Name | Type | Meaning |
|---|---|---|
| cmd | string | The command and its arguments, e.g. "say Hello" or "get key".
|
| ch | unitptr | The character who does it. |
Notes
- A move made with exec() is followed by a
lookin the new room, and programs that see the character's commands (awareones on the character itself, too) see that look as a command. chmust be a character: on an object, a room or null nothing happens.- This is the way to move an NPC through an exit:
exec("north", self)makes an ordinary move, with position checks, leave and arrive messages and every program that listens for movement. Uselink()only where there is no exit. - The program that calls
execdoesn't get the command itself (it is busy running), but the other programs onchand around it do, asSFB_CMD, and asSFB_DONEwhen the command succeeds. - Commands are at most 512 characters; a longer one is cut there and logged.
- A god (level 200 or more) can't be made to use a command that only gods have: it is refused and logged.
- If the command destroys
chor takes it away, and the program hassecuredch, the secure fires. - On a player it looks to them as if they typed it; use it on players with care.
Example
dilbegin go_east();
var
here : unitptr;
code
{
here := self.outside;
exec("east", self);
if (self.outside == here)
exec("say I can't get through here.", self);
return;
}
dilend
Walks an NPC east and checks that it got there.