Difference between revisions of "Manual:DIL Manual/exec()"
Jump to navigation
Jump to search
(checked against the compiler and the interpreter; example compiles) |
(corrected from the DIL keyword tests (T029-T043)) |
||
| Line 16: | Line 16: | ||
== Notes == | == 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. | * <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. | * 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. | ||
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.