Manual:DIL Manual/return
Jump to navigation
Jump to search
Contents
return
Instruction.
return; return (expression);
Ends the template that is running and goes back to the one that called it, which carries on after the call. A procedure (a template without a return type) uses return;. A function (dilbegin integer name(...), dilbegin string ...) must use return (value);, and the call gives that value.
Notes
- vmc checks the form:
return;in a function gives the error "no return expression expected" (meaning one is required), andreturn (x);in a procedure, or with a value of another type, gives "return expression not of correct type". - The value must have exactly the template's type.
return (null);doesn't compile in aunitptrfunction; return a unit variable that is null instead. - In a program that wasn't called by another (one started by
dilcopyor on a unit),returnends the program, asquitdoes. - Returning ends the template's
secure()s andinterrupt()s, and frees its local variables. A string, stringlist or intlist value is copied to the caller. - A function's result can't be passed straight into another DIL template call as an argument; put it in a variable first. Built-in functions such as
itoa()take it directly.
Example
dilbegin unitptr firstpc(room : unitptr);
var
u : unitptr;
code
{
u := room.inside;
while (u != null)
{
if (u.type == UNIT_ST_PC)
return (u);
u := u.next;
}
return (u);
}
dilend
dilbegin greetpc(u : unitptr);
code
{
if (u == null)
return;
act("Welcome, $1n.", A_SOMEONE, u, null, null, TO_CHAR);
return;
}
dilend
dilbegin greeter();
external
unitptr firstpc@ex(room : unitptr);
greetpc@ex(u : unitptr);
var
pc : unitptr;
code
{
heartbeat := PULSE_SEC * 10;
:start:
pause;
pc := firstpc@ex(self.outside);
greetpc@ex(pc);
goto start;
}
dilend
A function that returns the first player in a room (or null), and a procedure that returns early when there is nobody to greet.