Manual:DIL Manual/return()
Jump to navigation
Jump to search
Contents
return
Instruction. Leaves a procedure, or a function with its value.
return; return(value);
return; leaves a procedure (a template without a return type) and goes on in the
template that called it. return(value); leaves a function and gives
value to the caller; the value must have the type the function was declared
with (dilbegin integer f(...)).
In the template a unit runs (the one copied onto it with dilcopy) there is no
caller, and return; ends the program like quit.
Notes
- vmc checks the form:
return;in a function gives "no return expression expected",return(x);in a procedure, or with a value of the wrong type, "return expression not of correct type". return(null);doesn't compile in aunitptrfunction:nullhas a type of its own. Return a unit variable that is null instead (see the example on while()).- If the value fails at run time (a field of a null unit, e.g.
return(u.level);withunull),vme.logsays "DIL: Error return types do not match." and the whole program stops. Test for null first. - quit in a procedure or function doesn't return: it ends the whole program, callers too.
- Secures made in the template end when it returns.
- A string or a list is copied for the caller.
Example
dilbegin integer is_mortal(u : unitptr);
code
{
if (u.type != UNIT_ST_PC)
return(FALSE);
return(u.level < IMMORTAL_LEVEL);
}
dilend
dilbegin greet_mortal(u : unitptr);
external
integer is_mortal(u : unitptr);
var
i : integer;
code
{
i := is_mortal(u);
if (i == FALSE)
return; // back to the caller
exec("bow " + u.name, self);
return;
}
dilend
A function that tells whether a unit is a mortal player, and a procedure that leaves early when it isn't.