Difference between revisions of "Manual:DIL Manual/activator"

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="activator"></span>
+
= activator =
−
'activator'
+
'''Variable''' (unitptr, read-only).
−
    This variable is a unit pointer to the unit which activated the DIL
 
−
    program. It is set if 'activator' issued a command or unknown command
 
−
    and the program was setup to catch it, with : wait (SFB_CMD...).
 
−
    See description of messages for more information.
 
  
−
  ---~---~---~---~---~---~---~---~---
+
  activator : unitptr
−
<span id="activator"></span>
 
−
'activator'
 
−
    This variable is a unit pointer to the unit which activated the DIL
 
−
    program. It is set if 'activator' issued a command or unknown command
 
−
    and the program was setup to catch it, with : wait (SFB_CMD...).
 
−
    See description of messages for more information.
 
  
−
---~---~---~---~---~---~---~---~---
+
The unit that caused the event that woke the program:
 +
* SFB_CMD: the character who typed the command.
 +
* SFB_DONE and SFB_PRE: the one who acted (who gave, moved, hit, cast).
 +
* SFB_MSG: the unit whose program sent the message (sendto(), send(), sendtoalldil()).
 +
* SFB_DEAD: the character who died. SFB_COM: the character fighting.
 +
* SFB_TICK: null.
 +
 
 +
== Notes ==
 +
* It describes the current event only. After the next wait() or pause it belongs to another event, and a tick has no activator. Take it into a variable right after the wait, and secure() that variable to keep it: unit variables that aren't secured are null after every wake.
 +
* The first time a player command written in DIL (<code>func =</code> in commands.def) runs, activator is null; the player is <code>self</code> there.
 +
* It can't be assigned (<code>activator := u</code> is "Illegal lvalue").
 +
* In a wait condition, <code>activator.type == UNIT_ST_PC</code> also keeps out ticks: with no activator the field fails and the comparison is false.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin greet_back();
 +
var
 +
  pc : unitptr;
 +
code
 +
{
 +
  heartbeat := PULSE_SEC * 2;
 +
 
 +
  :start:
 +
  wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC) and
 +
                ("hello" in argument));
 +
  pc := activator;
 +
  secure(pc, lost);
 +
  pause;
 +
  exec("say Hello, " + pc.name + "!", self);
 +
  unsecure(pc);
 +
  goto start;
 +
 
 +
  :lost:
 +
  goto start;
 +
}
 +
dilend
 +
</pre>
 +
An NPC that answers a player who says "hello", after a pause. The player is kept in <code>pc</code> and secured, because after the pause <code>activator</code> belongs to the tick.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/self|self]]
 +
* [[Manual:DIL Manual/medium|medium]]
 +
* [[Manual:DIL Manual/target|target]]
 +
* [[Manual:DIL Manual/secure()|secure()]]
 +
* [[Manual:DIL Manual/wait()|wait()]]
 +
* [[Manual:DIL Manual/Messages|Messages]]

Latest revision as of 23:18, 14 November 2026

activator

Variable (unitptr, read-only).

activator : unitptr

The unit that caused the event that woke the program:

  • SFB_CMD: the character who typed the command.
  • SFB_DONE and SFB_PRE: the one who acted (who gave, moved, hit, cast).
  • SFB_MSG: the unit whose program sent the message (sendto(), send(), sendtoalldil()).
  • SFB_DEAD: the character who died. SFB_COM: the character fighting.
  • SFB_TICK: null.

Notes

  • It describes the current event only. After the next wait() or pause it belongs to another event, and a tick has no activator. Take it into a variable right after the wait, and secure() that variable to keep it: unit variables that aren't secured are null after every wake.
  • The first time a player command written in DIL (func = in commands.def) runs, activator is null; the player is self there.
  • It can't be assigned (activator := u is "Illegal lvalue").
  • In a wait condition, activator.type == UNIT_ST_PC also keeps out ticks: with no activator the field fails and the comparison is false.

Example

dilbegin greet_back();
var
   pc : unitptr;
code
{
   heartbeat := PULSE_SEC * 2;

   :start:
   wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC) and
                 ("hello" in argument));
   pc := activator;
   secure(pc, lost);
   pause;
   exec("say Hello, " + pc.name + "!", self);
   unsecure(pc);
   goto start;

   :lost:
   goto start;
}
dilend

An NPC that answers a player who says "hello", after a pause. The player is kept in pc and secured, because after the pause activator belongs to the tick.

See also