Difference between revisions of "Manual:DIL Manual/goto"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = goto = | |
| − | + | '''Instruction.''' Jumps to a label. | |
| − | |||
| − | |||
| − | |||
| − | + | goto name; | |
| + | ... | ||
| + | :name: | ||
| + | statement | ||
| − | + | A label is a name between colons in front of a statement. <code>goto</code> 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 <code>wait</code> or <code>pause</code>, the work, and <code>goto</code> back to the label. | |
| − | + | == Notes == | |
| − | + | * A label must be followed by a statement: <code>:done: }</code> is a syntax error. Write <code>:done: quit;</code> or <code>:done: return;</code>. | |
| − | + | * Labels belong to one template (<code>dilbegin ... dilend</code>); 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: <code>:Start:</code> and <code>:start:</code> are the same label. | ||
| + | * Several labels may stand in front of one statement. | ||
| + | * A loop that never waits (no <code>wait</code>, <code>pause</code> 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 <code>on ... goto</code>, <code>interrupt()</code>, <code>on_activation()</code> and <code>secure()</code>. | ||
| − | + | == Example == | |
| − | < | + | <pre> |
| − | + | 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 | ||
| + | </pre> | ||
| + | An NPC that calls out once a minute while standing. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/on()|on()]] | |
| − | + | * [[Manual:DIL Manual/if()|if()]] | |
| − | + | * [[Manual:DIL Manual/while()|while()]] | |
| − | + | * [[Manual:DIL Manual/wait()|wait()]] | |
| − | + | * [[Manual:DIL Manual/secure()|secure()]] | |
| − | + | * [[Manual:DIL Manual/interrupt()|interrupt()]] | |
| + | * [[Manual:DIL Manual/DIL Constructs|DIL Constructs]] | ||
Latest revision as of 23:23, 14 November 2026
Contents
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,pauseor 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()andsecure().
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.