Difference between revisions of "Manual:DIL Manual/exec()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
 
(corrected from the DIL keyword tests (T029-T043))
 
(2 intermediate revisions by 2 users 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)
  
−
<span id="bpexec"></span>
+
<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.
−
exec ( s : string , u : unitptr )
 
−
    s : Command and arguments to perform.
 
−
    u : Unit to perform command.
 
−
    result: Unit (PC/NPC) executes command. The argument is treated just as
 
−
            if a normal PC entered a command at the command prompt in the
 
−
            game. It is not directly possible to detect whether the command
 
−
            was a success or fail. For example, you might force a PC to
 
−
            "get key". If there is no 'key' available, the PC will get
 
−
            notified the normal way. Plenty of examples are given above.
 
  
−
---~---~---~---~---~---~---~---~---
+
== 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 look in the new room, and programs that see the character's commands (aware ones on the character itself, too) see that look as a command.
  • ch must 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. Use link() only where there is no exit.
  • The program that calls exec doesn't get the command itself (it is busy running), but the other programs on ch and around it do, as SFB_CMD, and as SFB_DONE 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 ch or takes it away, and the program has secured ch, 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.

See also