Difference between revisions of "Manual:DIL Manual/sendto()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = sendto() = | |
| − | + | '''Procedure.''' Sends a message to the DIL programs on one unit. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | sendto(msg : string, u : unitptr) | |
| − | |||
| − | sendto ( | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Every DIL program on <code>u</code> 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>sendto()</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. | |
| + | |||
| + | The unit can be anywhere in the game. Only the programs on <code>u</code> itself get the message, not those on what it contains. | ||
| + | |||
| + | == Parameters == | ||
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | msg || string || The message. Receivers usually compare it with <code>argument</code>. | ||
| + | |- | ||
| + | | u || unitptr || The unit whose programs get it. | ||
| + | |} | ||
| + | |||
| + | == Notes == | ||
| + | * <code>sendto(msg, self)</code> reaches the other programs on the sender's own unit, aware or not. The sending program itself never gets its own message. | ||
| + | * A program that isn't waiting for <code>SFB_MSG</code> at that moment misses the message; it isn't kept for later. | ||
| + | * The programs on <code>u</code> get it in [[Manual:DIL Manual/fnpri|fnpri]] order. One that does [[Manual:DIL Manual/block|block]] or holds [[Manual:DIL Manual/priority|priority]] keeps it from the ones after it. | ||
| + | * Nothing happens when <code>u</code> or the message is null. | ||
| + | * Afterwards the sender's secures are tested: if a receiver moved a secured unit away, the sender goes to that secure's label. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin call_captain(); | ||
| + | var | ||
| + | capt : unitptr; | ||
| + | code | ||
| + | { | ||
| + | heartbeat := PULSE_SEC * 30; | ||
| + | :start: | ||
| + | wait(SFB_COM, TRUE); | ||
| + | capt := findsymbolic("captain@ex"); | ||
| + | if (capt != null) | ||
| + | sendto("alarm " + self.outside.name, capt); | ||
| + | pause; | ||
| + | goto start; | ||
| + | } | ||
| + | dilend | ||
| + | |||
| + | dilbegin captain(); | ||
| + | code | ||
| + | { | ||
| + | :start: | ||
| + | wait(SFB_MSG, "alarm" in argument); | ||
| + | exec("shout To arms! " + activator.name + " needs help!", self); | ||
| + | goto start; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | A guard in a fight calls the captain, wherever the captain is, at most every 30 seconds. In haon_dor.zon the orc chief tells Mary she has lost her pot with <code>sendto("gotit", u1)</code>. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/send()|send()]] | ||
| + | * [[Manual:DIL Manual/sendtoall()|sendtoall()]] | ||
| + | * [[Manual:DIL Manual/sendtoalldil()|sendtoalldil()]] | ||
| + | * [[Manual:DIL Manual/findsymbolic()|findsymbolic()]] | ||
| + | * [[Manual:DIL Manual/SFB MSG|SFB_MSG]] | ||
Latest revision as of 23:16, 14 November 2026
sendto()
Procedure. Sends a message to the DIL programs on one unit.
sendto(msg : string, u : unitptr)
Every DIL program on u that is waiting for SFB_MSG (in a wait() or an interrupt()) gets the message. The receivers run at once, before sendto() returns. In each of them argument is the message and activator is the sender's unit; medium and target are null.
The unit can be anywhere in the game. Only the programs on u itself get the message, not those on what it contains.
Parameters
| Name | Type | Meaning |
|---|---|---|
| msg | string | The message. Receivers usually compare it with argument.
|
| u | unitptr | The unit whose programs get it. |
Notes
sendto(msg, self)reaches the other programs on the sender's own unit, aware or not. The sending program itself never gets its own message.- A program that isn't waiting for
SFB_MSGat that moment misses the message; it isn't kept for later. - The programs on
uget it in fnpri order. One that does block or holds priority keeps it from the ones after it. - Nothing happens when
uor the message is null. - Afterwards the sender's secures are tested: if a receiver moved a secured unit away, the sender goes to that secure's label.
Example
dilbegin call_captain();
var
capt : unitptr;
code
{
heartbeat := PULSE_SEC * 30;
:start:
wait(SFB_COM, TRUE);
capt := findsymbolic("captain@ex");
if (capt != null)
sendto("alarm " + self.outside.name, capt);
pause;
goto start;
}
dilend
dilbegin captain();
code
{
:start:
wait(SFB_MSG, "alarm" in argument);
exec("shout To arms! " + activator.name + " needs help!", self);
goto start;
}
dilend
A guard in a fight calls the captain, wherever the captain is, at most every 30 seconds. In haon_dor.zon the orc chief tells Mary she has lost her pot with sendto("gotit", u1).