Difference between revisions of "Manual:DIL Manual/send()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = send() = | |
| − | + | '''Procedure.''' Sends a message to the DIL programs around the unit. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | send(msg : string) | |
| − | |||
| − | send ( | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Every DIL program around the program's own unit that is waiting for <code>SFB_MSG</code> (in a [[Manual:DIL Manual/wait()|wait()]] or an [[Manual:DIL Manual/interrupt()|interrupt()]]) gets the message. The receivers run at once, before <code>send()</code> returns. In each of them [[Manual:DIL Manual/argument|argument]] is the message and [[Manual:DIL Manual/activator|activator]] is the sender's unit; [[Manual:DIL Manual/medium|medium]] and [[Manual:DIL Manual/target|target]] are null. | |
| + | |||
| + | "Around" is the unit the sender is in (usually a room, but it can be a character or a container), and in this order: | ||
| + | * the programs on that unit itself; | ||
| + | * what the sender contains (its inventory and equipment); | ||
| + | * every unit in it, and what is in the transparent ones there; | ||
| + | * what the characters there wear, but not what they carry. | ||
| + | A sender that is a room reaches the units directly in it. | ||
| + | |||
| + | == Parameters == | ||
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | msg || string || The message. Receivers usually compare it with <code>argument</code>. | ||
| + | |} | ||
| + | |||
| + | == Notes == | ||
| + | * The sending program never gets its own message. The other programs on the sender's unit get it only if they are [[Manual:DIL Manual/aware|aware]]. | ||
| + | * A program that isn't waiting for <code>SFB_MSG</code> at that moment misses the message; it isn't kept for later. | ||
| + | * A receiver that does [[Manual:DIL Manual/block|block]] stops the message there: the units after it don't get it. A receiver holding [[Manual:DIL Manual/priority|priority]] keeps it from the later programs on its own unit. | ||
| + | * Afterwards the sender's secures are tested: if a receiver moved a secured unit away, the sender goes to that secure's label. | ||
| + | * An empty (null) string sends nothing. | ||
| + | * To reach the programs on one particular unit use [[Manual:DIL Manual/sendto()|sendto()]]; for every copy of a template in the game, [[Manual:DIL Manual/sendtoalldil()|sendtoalldil()]]. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin dinner_bell(); | ||
| + | code | ||
| + | { | ||
| + | :start: | ||
| + | wait(SFB_CMD, command("pull") and (activator.type == UNIT_ST_PC)); | ||
| + | block; | ||
| + | act("You pull the rope and the bell rings.", A_ALWAYS, activator, null, null, TO_CHAR); | ||
| + | act("$1n pulls the rope and the bell rings.", A_ALWAYS, activator, null, null, TO_ROOM); | ||
| + | send("dinner"); | ||
| + | goto start; | ||
| + | } | ||
| + | dilend | ||
| + | |||
| + | dilbegin hungry_orc(); | ||
| + | code | ||
| + | { | ||
| + | :start: | ||
| + | wait(SFB_MSG, argument == "dinner"); | ||
| + | exec("say Food!", self); | ||
| + | goto start; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | A bell (an object in the room) tells everyone there that dinner is served, and each orc with <code>hungry_orc</code> answers. The orc chief in haon_dor.zon calls his orcs the same way with <code>send("stew")</code>. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/sendto()|sendto()]] | ||
| + | * [[Manual:DIL Manual/sendtoall()|sendtoall()]] | ||
| + | * [[Manual:DIL Manual/sendtoalldil()|sendtoalldil()]] | ||
| + | * [[Manual:DIL Manual/SFB MSG|SFB_MSG]] | ||
| + | * [[Manual:DIL Manual/Messages|Messages]] | ||
Latest revision as of 23:16, 14 November 2026
send()
Procedure. Sends a message to the DIL programs around the unit.
send(msg : string)
Every DIL program around the program's own unit that is waiting for SFB_MSG (in a wait() or an interrupt()) gets the message. The receivers run at once, before send() returns. In each of them argument is the message and activator is the sender's unit; medium and target are null.
"Around" is the unit the sender is in (usually a room, but it can be a character or a container), and in this order:
- the programs on that unit itself;
- what the sender contains (its inventory and equipment);
- every unit in it, and what is in the transparent ones there;
- what the characters there wear, but not what they carry.
A sender that is a room reaches the units directly in it.
Parameters
| Name | Type | Meaning |
|---|---|---|
| msg | string | The message. Receivers usually compare it with argument.
|
Notes
- The sending program never gets its own message. The other programs on the sender's unit get it only if they are aware.
- A program that isn't waiting for
SFB_MSGat that moment misses the message; it isn't kept for later. - A receiver that does block stops the message there: the units after it don't get it. A receiver holding priority keeps it from the later programs on its own unit.
- Afterwards the sender's secures are tested: if a receiver moved a secured unit away, the sender goes to that secure's label.
- An empty (null) string sends nothing.
- To reach the programs on one particular unit use sendto(); for every copy of a template in the game, sendtoalldil().
Example
dilbegin dinner_bell();
code
{
:start:
wait(SFB_CMD, command("pull") and (activator.type == UNIT_ST_PC));
block;
act("You pull the rope and the bell rings.", A_ALWAYS, activator, null, null, TO_CHAR);
act("$1n pulls the rope and the bell rings.", A_ALWAYS, activator, null, null, TO_ROOM);
send("dinner");
goto start;
}
dilend
dilbegin hungry_orc();
code
{
:start:
wait(SFB_MSG, argument == "dinner");
exec("say Food!", self);
goto start;
}
dilend
A bell (an object in the room) tells everyone there that dinner is served, and each orc with hungry_orc answers. The orc chief in haon_dor.zon calls his orcs the same way with send("stew").