Difference between revisions of "Manual:DIL Manual/send pre()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bfsend_pre"></span>
+
= send_pre() =
−
'''Function:'''</i><!--ENDCODE-->send_pre( c : string, a :unitptr, m : unitptr, t :unitptr, p : integer, arg : string, o : unitptr);</i><!--ENDCODE-->
+
'''Function''' (integer). Asks the programs around a character whether a command may go ahead.
  
−
  <!--TERM-->  '''c'''
+
  send_pre(cmd : string, who : unitptr, med : unitptr, tgt : unitptr, pwr : integer,
−
<!--DEFINITION-->        the command string that is sending the message
+
          arg : string, other : unitptr)
−
<!--TERM-->  '''a'''
 
−
<!--DEFINITION-->        the unitptr (activator) that activated the message
 
−
<!--TERM-->  '''m'''
 
−
<!--DEFINITION-->        the unitptr (medium) that the Dil is acting through
 
−
<!--TERM-->  '''t'''
 
−
<!--DEFINITION-->        the unitptr (target) the Dil is acting on
 
−
<!--TERM-->  '''p'''
 
−
<!--DEFINITION-->        the power of the message
 
−
<!--TERM-->  '''arg'''
 
−
<!--DEFINITION-->        the argument sent with the message
 
−
<!--TERM-->  '''o'''
 
−
<!--DEFINITION-->        the unitptr (other) you also want the message to go to
 
  
 +
When a DIL does something on a character's behalf that a command would normally do (moving,
 +
fleeing), other programs expect to hear about it first: a guard that blocks an exit waits with
 +
<code>wait(SFB_PRE, command("north") ...)</code>. send_pre() sends that <code>SFB_PRE</code>
 +
event as if <code>who</code> had typed the command, to the programs the command itself would
 +
reach: those in the room, on the room, and on what <code>who</code> carries. Each can let it pass
 +
or <code>block</code> it, and the answer tells the caller whether to go on.
  
 +
[[Manual:DIL Manual/send done()|send_done()]] is its partner, for the <code>SFB_DONE</code> event
 +
after the deed.
  
−
New Function send_pre() takes same arguments as send_done but returns either
+
== Parameters ==
−
  SFR_SHARE or SFR_BLOCK.
+
{| class="wikitable"
−
If the command is blocked by another special or dil, then SFB_BLOCK will be returned,
+
! Name !! Type !! Meaning
−
  and you should quit your dil.
+
|-
−
'''Example:'''
+
| cmd || string || The command, looked up like a typed command (<code>"north"</code>, <code>"flee"</code>). Receivers see it in <code>command(...)</code>.
−
<i><!--CODE-->
+
|-
−
---~---~---~---~---~---~---~---~---
+
| who || unitptr || Who does it: the receivers' <code>activator</code>.
−
 
+
|-
−
dilbegin cmdtst(arg : string);
+
| med || unitptr || The receivers' <code>medium</code>, or null.
−
var
+
|-
−
  i : integer;
+
| tgt || unitptr || The receivers' <code>target</code>, or null.
−
code
+
|-
−
dilend
+
| pwr || integer || The receivers' <code>power</code>.
−
 
+
|-
−
 
+
| arg || string || The receivers' <code>argument</code>.
−
dilbegin pretest();
+
|-
−
code
+
| other || unitptr || A unit outside the room that should hear it too, or null.
−
dilend
+
|}
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
  
 +
== Returns ==
 +
Integer, from <code>vme/include/vme.h</code>: <code>SFR_SHARE</code> when nobody blocked it,
 +
<code>SFR_BLOCK</code> when a program blocked it. Stop when you get <code>SFR_BLOCK</code>.
  
−
---~---~---~---~---~---~---~---~---
+
It fails, and writes "Can not send_preprocess. No such command" to the zone's log, when
−
<span id="bfsend_pre"></span>
+
<code>cmd</code> is empty or not a command. A wrong type in another argument also fails.
−
'''Function:'''</i><!--ENDCODE-->send_pre( c : string, a :unitptr, m : unitptr, t :unitptr, p : integer, arg : string, o : unitptr);</i><!--ENDCODE-->
 
  
−
<!--TERM--> '''c'''
+
== Notes ==
−
<!--DEFINITION-->         the command string that is sending the message
+
* With <code>who</code> null, nothing is sent and the result is <code>SFR_SHARE</code>.
−
<!--TERM--> '''a'''
+
* It sends the event; it doesn't run the command. Do the deed yourself afterwards, or use
−
<!--DEFINITION-->         the unitptr (activator) that activated the message
+
  [[Manual:DIL Manual/exec()|exec()]] when the real command will do.
−
<!--TERM-->  '''m'''
+
* A receiver changing <code>power</code> doesn't change your <code>pwr</code>.
−
<!--DEFINITION-->        the unitptr (medium) that the Dil is acting through
 
−
<!--TERM-->  '''t'''
 
−
<!--DEFINITION-->        the unitptr (target) the Dil is acting on
 
−
<!--TERM--> '''p'''
 
−
<!--DEFINITION-->        the power of the message
 
−
<!--TERM--> '''arg'''
 
−
<!--DEFINITION-->         the argument sent with the message
 
−
<!--TERM--> '''o'''
 
−
<!--DEFINITION-->        the unitptr (other) you also want the message to go to
 
  
 +
== Example ==
 +
<pre>
 +
dilbegin go_dir(dir : string, toroom : unitptr, arg : string);
 +
var
 +
  res : integer;
 +
code
 +
{
 +
  res := send_pre(dir, self, null, null, 0, arg, null);
 +
  if (res != SFR_SHARE)
 +
      quit;
  
−
 
+
  link(self, toroom);
−
New Function send_pre() takes same arguments as send_done but returns either
+
  act("$1n arrives.", A_HIDEINV, self, null, null, TO_ROOM);
−
  SFR_SHARE or SFR_BLOCK.
+
   quit;
−
If the command is blocked by another special or dil, then SFB_BLOCK will be returned,
+
}
−
  and you should quit your dil.
 
−
'''Example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
dilbegin cmdtst(arg : string);
 
−
var
 
−
   i : integer;
 
−
code
 
−
dilend
 
−
 
 
−
 
 
−
dilbegin pretest();
 
−
code
 
 
dilend
 
dilend
 +
</pre>
 +
Moves a character a special way only if no guard or door program blocks the direction, as the
 +
climbing code in basemove.zon does.
  
−
---~---~---~---~---~---~---~---~---
+
== See also ==
−
 
+
* [[Manual:DIL Manual/send done()|send_done()]]
−
</i><!--ENDCODE-->
+
* [[Manual:DIL Manual/exec()|exec()]]
−
 
+
* [[Manual:DIL Manual/block|block]]
−
 
+
* [[Manual:DIL Manual/wait()|wait()]]
−
---~---~---~---~---~---~---~---~---
+
* [[Manual:DIL Manual/command()|command()]]

Latest revision as of 23:20, 14 November 2026

send_pre()

Function (integer). Asks the programs around a character whether a command may go ahead.

send_pre(cmd : string, who : unitptr, med : unitptr, tgt : unitptr, pwr : integer,
         arg : string, other : unitptr)

When a DIL does something on a character's behalf that a command would normally do (moving, fleeing), other programs expect to hear about it first: a guard that blocks an exit waits with wait(SFB_PRE, command("north") ...). send_pre() sends that SFB_PRE event as if who had typed the command, to the programs the command itself would reach: those in the room, on the room, and on what who carries. Each can let it pass or block it, and the answer tells the caller whether to go on.

send_done() is its partner, for the SFB_DONE event after the deed.

Parameters

Name Type Meaning
cmd string The command, looked up like a typed command ("north", "flee"). Receivers see it in command(...).
who unitptr Who does it: the receivers' activator.
med unitptr The receivers' medium, or null.
tgt unitptr The receivers' target, or null.
pwr integer The receivers' power.
arg string The receivers' argument.
other unitptr A unit outside the room that should hear it too, or null.

Returns

Integer, from vme/include/vme.h: SFR_SHARE when nobody blocked it, SFR_BLOCK when a program blocked it. Stop when you get SFR_BLOCK.

It fails, and writes "Can not send_preprocess. No such command" to the zone's log, when cmd is empty or not a command. A wrong type in another argument also fails.

Notes

  • With who null, nothing is sent and the result is SFR_SHARE.
  • It sends the event; it doesn't run the command. Do the deed yourself afterwards, or use
 exec() when the real command will do.
  • A receiver changing power doesn't change your pwr.

Example

dilbegin go_dir(dir : string, toroom : unitptr, arg : string);
var
   res : integer;
code
{
   res := send_pre(dir, self, null, null, 0, arg, null);
   if (res != SFR_SHARE)
      quit;

   link(self, toroom);
   act("$1n arrives.", A_HIDEINV, self, null, null, TO_ROOM);
   quit;
}
dilend

Moves a character a special way only if no guard or door program blocks the direction, as the climbing code in basemove.zon does.

See also