Manual:DIL Manual/null
Jump to navigation
Jump to search
Contents
null
Keyword. The empty value: no unit, no extra, no zone, no command, no string, an empty list.
null
Use it to test whether a variable holds anything, to empty a variable, and as an argument where a function takes "no unit", as in act(..., self, null, null, TO_ROOM).
Notes
u == nullandu != nullwork for unitptr, extraptr, zoneptr and cmdptr. Many functions return null when they find nothing: findunit(), findroom(), findsymbolic(), load(), and"name" in u.extra.if (u)andwhile (u)also test for null.- Assigning null empties a variable of any pointer, string or list type:
u := null;,s := null;,sl := null;. An integer can't take null: vmc says "Assigning incompatible types". - A stringlist or intlist is equal to null when it is empty.
- A string is equal to null only when it holds no string at all (never set, or set to null). After
s := "";,s == nullis false. Test strings withs == "", which is true in both cases. - A field of null fails, and a failed value is false in every comparison: when
uis null,u.level > 5andu.level <= 5are both false.andandorevaluate both sides, so testif (u == null)on its own before usingu.
Example
dilbegin integer carries(pc : unitptr, keysym : string);
var
u : unitptr;
code
{
if (pc == null)
return (FALSE);
u := findsymbolic(pc, keysym, FIND_UNIT_INVEN | FIND_UNIT_EQUIP);
return (u != null);
}
dilend
Tells whether a player carries or wears a unit, by its symbolic name ("key@zone"); a null player gives FALSE.