Difference between revisions of "Manual:DIL Manual/SFB MSG"

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="sfbmsg"></span>
+
= SFB_MSG =
 +
'''Constant''' (integer, vme.h: 0x0040).
  
−
  SFB_MSG           User message
+
  wait(SFB_MSG, condition)
  
−
  When this flag is set, the routine gets activated when a message is passed
+
The message event: how DIL programs talk to each other. A program sends a text with <code>send()</code>, <code>sendto()</code>, <code>sendtoall()</code> or <code>sendtoalldil()</code>; a program waiting with <code>SFB_MSG</code> wakes with the text in <code>argument</code>.
−
  to it. Messages can be passed with the DIL commands 'sendto' and 'send':
 
  
−
      'activator'... is a unitptr to the unit sending the message.
+
== What the event holds ==
−
      'argument'.... is a string containing possible data from the sender.
+
{| class="wikitable"
 +
! Variable !! Value
 +
|-
 +
| activator || the unit whose program sent the message
 +
|-
 +
| argument || the text that was sent
 +
|-
 +
| command(CMD_AUTO_MSG) || TRUE
 +
|-
 +
| medium || null; with <code>sendtoall()</code> and <code>sendtoalldil()</code> the sender too
 +
|-
 +
| target || null; with <code>sendtoalldil()</code> the unit receiving it
 +
|}
  
−
      command(CMD_AUTO_MSG) will evaluate to true.
+
== Who gets it ==
 +
* <code>send(msg)</code>: the sender's surroundings, as a command (see [[Manual:DIL Manual/SFB CMD|SFB_CMD]]). The other programs on the sending unit get it only if they are declared <code>aware</code>.
 +
* <code>sendto(msg, u)</code>: every program on <code>u</code>, the sender's own programs too when <code>u</code> is the sender.
 +
* <code>sendtoall(msg, "sym@zone")</code>: the programs on every copy of that unit in the game.
 +
* <code>sendtoalldil(msg, "tmpl@zone")</code>: every running copy of that template, except the one sending.
  
 +
== Notes ==
 +
* A program that is running can't be woken. While the sender is still busy after its send, a message sent back to it is lost; it can only be caught by programs that are waiting.
 +
* Messages are not queued: a program that is busy, or waiting for another kind of event, misses them. Use <code>interrupt(SFB_MSG, ...)</code> to catch a message while waiting for something else.
 +
* Compare texts with <code>==</code> (which ignores case) or test words with <code>in</code>.
  
−
  Messages are normally not generated by actions performed by the owner of the
+
== Example ==
−
  program. For a program to be able to be aware of messages from the owner, a
+
<pre>
−
   keyword 'aware' should be listed just after 'dilbegin'.
+
dilbegin herald();
 +
code
 +
{
 +
   heartbeat := PULSE_SEC * 5;
  
−
   When a unit is saved, normally, the DIL programs in it would restart when the
+
   :start:
−
   program is loaded. However it is possible to let DIL programs recall their
+
   wait(SFB_MSG, argument == "gate open");
−
  execution from where they left off when they where saved.  This is done by
 
−
  listing the keyword 'recall' after the 'dilbegin'.  This is however a bit
 
−
  limited.  Only the status of the original template are saved. Not the state
 
−
  inside a template called as a function or procedure from inside the original
 
−
  template. 'secure' and interrupts are not recalled upon loading the template.
 
  
 +
  exec("shout The gate stands open!", self);
 +
  goto start;
 +
}
 +
dilend
  
−
'''Example:'''
+
dilbegin gatekeeper();
 +
code
 +
{
 +
  :start:
 +
  wait(SFB_CMD, command("say") and ("open sesame" in argument));
  
−
<nowiki>
+
  send("gate open");
 +
  goto start;
 +
}
 +
dilend
 +
</pre>
 +
When a player says "open sesame" next to the gatekeeper, it tells the room, and a herald in the same room shouts the news.
  
−
dilbegin recall aware mute();
+
== See also ==
−
var
+
* [[Manual:DIL Manual/send()|send()]]
−
    i : integer;
+
* [[Manual:DIL Manual/sendto()|sendto()]]
−
 
+
* [[Manual:DIL Manual/sendtoall()|sendtoall()]]
−
code
+
* [[Manual:DIL Manual/sendtoalldil()|sendtoalldil()]]
−
dilend</nowiki>
+
* [[Manual:DIL Manual/interrupt()|interrupt()]]
−
 
+
* [[Manual:DIL Manual/aware|aware]]
−
/* When attached to a PC, the pc will be unable to utter a sound the first 10
 
−
    sound command, and blood will spurt out.
 
−
    The next 10 sound commands, the victim just can't shout.
 
−
    The last 10 sound commands only say will work.
 
−
    In the end, 'quit' removes the program all together.
 
−
    The smart thing is that the 'aware' keyword lets the program receive messages
 
−
    from the owner (player) commands. Secondly, the keyword 'recall' makes sure
 
−
    that the program does not start over, if the victim quits in the middle, but
 
−
    restart at the position it had attained.
 
−
    Do not put in the 'aware' if it is not needed. It saves some interpretation
 
−
    time not having to pass the extra messages.
 
−
*/
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
<span id="sfbmsg"></span>
 
−
 
 
−
SFB_MSG            User message
 
−
 
 
−
  When this flag is set, the routine gets activated when a message is passed
 
−
  to it. Messages can be passed with the DIL commands 'sendto' and 'send':
 
−
 
 
−
      'activator'... is a unitptr to the unit sending the message.
 
−
      'argument'.... is a string containing possible data from the sender.
 
−
 
 
−
      command(CMD_AUTO_MSG) will evaluate to true.
 
−
 
 
−
 
 
−
  Messages are normally not generated by actions performed by the owner of the
 
−
  program. For a program to be able to be aware of messages from the owner, a
 
−
  keyword 'aware' should be listed just after 'dilbegin'.
 
−
 
 
−
  When a unit is saved, normally, the DIL programs in it would restart when the
 
−
  program is loaded. However it is possible to let DIL programs recall their
 
−
  execution from where they left off when they where saved.  This is done by
 
−
  listing the keyword 'recall' after the 'dilbegin'.  This is however a bit
 
−
  limited.  Only the status of the original template are saved. Not the state
 
−
  inside a template called as a function or procedure from inside the original
 
−
  template. 'secure' and interrupts are not recalled upon loading the template.
 
−
 
 
−
 
 
−
'''Example:'''
 
−
 
 
−
<nowiki>
 
−
 
 
−
dilbegin recall aware mute();
 
−
var
 
−
    i : integer;
 
−
 
 
−
code
 
−
dilend</nowiki>
 
−
 
 
−
/* When attached to a PC, the pc will be unable to utter a sound the first 10
 
−
    sound command, and blood will spurt out.
 
−
    The next 10 sound commands, the victim just can't shout.
 
−
    The last 10 sound commands only say will work.
 
−
    In the end, 'quit' removes the program all together.
 
−
    The smart thing is that the 'aware' keyword lets the program receive messages
 
−
    from the owner (player) commands. Secondly, the keyword 'recall' makes sure
 
−
    that the program does not start over, if the victim quits in the middle, but
 
−
    restart at the position it had attained.
 
−
    Do not put in the 'aware' if it is not needed. It saves some interpretation
 
−
    time not having to pass the extra messages.
 
−
*/
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:24, 14 November 2026

SFB_MSG

Constant (integer, vme.h: 0x0040).

wait(SFB_MSG, condition)

The message event: how DIL programs talk to each other. A program sends a text with send(), sendto(), sendtoall() or sendtoalldil(); a program waiting with SFB_MSG wakes with the text in argument.

What the event holds

Variable Value
activator the unit whose program sent the message
argument the text that was sent
command(CMD_AUTO_MSG) TRUE
medium null; with sendtoall() and sendtoalldil() the sender too
target null; with sendtoalldil() the unit receiving it

Who gets it

  • send(msg): the sender's surroundings, as a command (see SFB_CMD). The other programs on the sending unit get it only if they are declared aware.
  • sendto(msg, u): every program on u, the sender's own programs too when u is the sender.
  • sendtoall(msg, "sym@zone"): the programs on every copy of that unit in the game.
  • sendtoalldil(msg, "tmpl@zone"): every running copy of that template, except the one sending.

Notes

  • A program that is running can't be woken. While the sender is still busy after its send, a message sent back to it is lost; it can only be caught by programs that are waiting.
  • Messages are not queued: a program that is busy, or waiting for another kind of event, misses them. Use interrupt(SFB_MSG, ...) to catch a message while waiting for something else.
  • Compare texts with == (which ignores case) or test words with in.

Example

dilbegin herald();
code
{
   heartbeat := PULSE_SEC * 5;

   :start:
   wait(SFB_MSG, argument == "gate open");

   exec("shout The gate stands open!", self);
   goto start;
}
dilend

dilbegin gatekeeper();
code
{
   :start:
   wait(SFB_CMD, command("say") and ("open sesame" in argument));

   send("gate open");
   goto start;
}
dilend

When a player says "open sesame" next to the gatekeeper, it tells the room, and a herald in the same room shouts the news.

See also