Manual:DIL Manual/goto

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:23, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

goto

Instruction. Jumps to a label.

goto name;
...
:name:
statement

A label is a name between colons in front of a statement. goto carries on from there. It can jump forwards and backwards, and out of loops and blocks. The usual DIL program is a loop: a label, a wait or pause, the work, and goto back to the label.

Notes

  • A label must be followed by a statement: :done: } is a syntax error. Write :done: quit; or :done: return;.
  • Labels belong to one template (dilbegin ... dilend); a goto can't leave it.
  • vmc refuses a label that is never defined ("Undefined label: ...") and one defined twice ("Redefinition of label"). Names ignore case: :Start: and :start: are the same label.
  • Several labels may stand in front of one statement.
  • A loop that never waits (no wait, pause or other wait) is stopped by the server: it logs "DIL ... had endless loop." in the zone's log and removes the program.
  • Labels are also used by on ... goto, interrupt(), on_activation() and secure().

Example

dilbegin fish_monger();
code
{
   heartbeat := PULSE_SEC * 60;

   :loop:
   pause;
   if (self.position < POSITION_STANDING)
      goto loop;
   exec("say Fresh fish! Fresh fish!", self);
   goto loop;
}
dilend

An NPC that calls out once a minute while standing.

See also