Manual:DIL Manual/skip

From DikuMUD Wiki
Jump to navigation Jump to search

skip

Keyword. Takes the place of a label in an interrupt or an on ... goto, and means "don't jump".

on_activation(condition, skip);
interrupt(flags, condition, skip);
on expression goto label0, skip, label2, ...;

skip is accepted in two places only: as the label of interrupt() (and of on_activation(), which is interrupt(SFB_ACTIVATE, ...), a macro in wmacros.h), and in the label list of on ... goto.

In an interrupt, skip means: while the condition holds, ignore the event. The program isn't run for it and stays in the wait it was in. The event is lost, not queued, and the unit's other programs still get it. The usual use is a guard at the top of a program: asleep or fighting, ignore everything.

In on ... goto, a skip entry means: for this value, don't jump; go on with the statement after the on, as for a value outside the list.

Notes

  • skip is a reserved word: it can't name a variable or a label, and goto skip; is a syntax error.
  • The condition is tested at every wake of the program (check_interrupt in dilrun.cpp), before the program sees the event.
  • An on_activation() with a label is cleared when it jumps; one with skip stays until the template returns or clear() removes it. on_activation() returns the interrupt's number for clear(), as in haon_dor.zon: intridx := on_activation(self.position <= POSITION_SLEEPING, skip);
  • The condition is evaluated in full (and and or don't short-circuit), and a field of a null unit is false, so activator.position <= POSITION_SLEEPING is false when there is no activator.

Example

dilbegin fortune();
var
   i : integer;
code
{
   on_activation((self.position <= POSITION_SLEEPING) or
                 (self.position == POSITION_FIGHTING), skip);
   heartbeat := PULSE_SEC * 30;

   :start:
   wait(SFB_TICK, TRUE);
   i := rnd(0, 3);
   on i goto good, skip, bad;
   exec("say The stars are silent today.", self);
   goto start;

   :good:
   exec("say Fortune smiles on you.", self);
   goto start;

   :bad:
   exec("say Beware the dark.", self);
   goto start;
}
dilend

A fortune teller who speaks every 30 seconds while awake and not fighting. When rnd() gives 1 (skip) or 3 (past the end of the list), the on falls through to the line after it.

See also