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)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= 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)
  
−
<span id="bfsend_pre"></span>
+
When a DIL does something on a character's behalf that a command would normally do (moving,
−
'''Function:'''</i><!--ENDCODE-->send_pre( c : string, a :unitptr, m : unitptr, t :unitptr, p : integer, arg : string, o : unitptr);</i><!--ENDCODE-->
+
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.
  
−
<!--TERM-->  '''c'''
+
[[Manual:DIL Manual/send done()|send_done()]] is its partner, for the <code>SFB_DONE</code> event
−
<!--DEFINITION-->        the command string that is sending the message
+
after the deed.
−
<!--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
 
  
 +
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| cmd || string || The command, looked up like a typed command (<code>"north"</code>, <code>"flee"</code>). Receivers see it in <code>command(...)</code>.
 +
|-
 +
| who || unitptr || Who does it: the receivers' <code>activator</code>.
 +
|-
 +
| med || unitptr || The receivers' <code>medium</code>, or null.
 +
|-
 +
| tgt || unitptr || The receivers' <code>target</code>, or null.
 +
|-
 +
| pwr || integer || The receivers' <code>power</code>.
 +
|-
 +
| arg || string || The receivers' <code>argument</code>.
 +
|-
 +
| other || unitptr || A unit outside the room that should hear it too, or null.
 +
|}
  
 +
== 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>.
  
−
New Function send_pre() takes same arguments as send_done but returns either
+
It fails, and writes "Can not send_preprocess. No such command" to the zone's log, when
−
  SFR_SHARE or SFR_BLOCK.
+
<code>cmd</code> is empty or not a command. A wrong type in another argument also fails.
−
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);
+
== Notes ==
−
var
+
* With <code>who</code> null, nothing is sent and the result is <code>SFR_SHARE</code>.
−
  i : integer;
+
* It sends the event; it doesn't run the command. Do the deed yourself afterwards, or use
−
code
+
  [[Manual:DIL Manual/exec()|exec()]] when the real command will do.
−
{
+
* A receiver changing <code>power</code> doesn't change your <code>pwr</code>.
−
    i:=send_pre("cmdtest",self,null,null,0,argument,null);
 
  
−
if (i == SFR_BLOCK)
+
== 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);
 +
  act("$1n arrives.", A_HIDEINV, self, null, null, TO_ROOM);
 
   quit;
 
   quit;
 +
}
 +
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.
  
−
          sendtext ("No one blocked me!&amp;n",self);
+
== See also ==
−
          quit;
+
* [[Manual:DIL Manual/send done()|send_done()]]
−
          }
+
* [[Manual:DIL Manual/exec()|exec()]]
−
          dilend
+
* [[Manual:DIL Manual/block|block]]
−
 
+
* [[Manual:DIL Manual/wait()|wait()]]
−
 
+
* [[Manual:DIL Manual/command()|command()]]
−
dilbegin pretest();
 
−
code
 
−
{
 
−
    :loop:
 
−
    wait(SFB_PRE, command("cmdtest"));
 
−
    block;
 
−
        act("hahahaha I blocked your cmdtest command",
 
−
        A_SOMEONE, activator, medium, null, TO_ALL);
 
−
        goto loop;
 
−
}
 
−
dilend
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

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