Manual:DIL Manual/null

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:18, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 == null and u != null work 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) and while (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 == null is false. Test strings with s == "", which is true in both cases.
  • A field of null fails, and a failed value is false in every comparison: when u is null, u.level > 5 and u.level <= 5 are both false. and and or evaluate both sides, so test if (u == null) on its own before using u.

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.

See also