Manual:DIL Manual/activator
Jump to navigation
Jump to search
Contents
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 isselfthere. - It can't be assigned (
activator := uis "Illegal lvalue"). - In a wait condition,
activator.type == UNIT_ST_PCalso 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.