Manual:DIL Manual/code
Jump to navigation
Jump to search
Contents
code
Keyword. Starts the statements of a template.
code
{
statements
}
Every template has a code section, after var and before dilend. The statements go inside one pair of braces. Labels for goto and secure are written :name: on a line of their own.
A program copied onto a unit starts at the first statement, and stops at quit. A called procedure or function goes back to its caller at return.
Notes
- The braces must hold at least one statement: an empty
{ }is a syntax error. - vmc ends the code with a jump back to the first statement. A program that reaches the closing brace starts over from the top, with its variables as they were. That is a way to write a loop, but a program that never waits ends up stopped by the server as "had endless loop".
- A called template that reaches the closing brace also starts over instead of returning to its caller. End procedures with
return;and functions withreturn(value);on every path. - Statements are separated by semicolons; a block
{ ... }groups statements forif,whileand the like.
Example
dilbegin chimes();
var
n : integer;
code
{
heartbeat := PULSE_SEC * 30;
pause;
n := n + 1;
if (n > 3)
{
act("The chimes fall silent.", A_ALWAYS, self, null, null, TO_ALL);
quit;
}
act("The chimes ring " + itoa(n) + " times.", A_ALWAYS, self, null, null, TO_ALL);
}
dilend
On an object (dilcopy chimes@ex(); in its definition): every 30 seconds it rings, running from the top again each time it reaches the closing brace, and stops after the third time.