Difference between revisions of "Manual:DIL Manual/null"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="null"></span>
+
= null =
−
'null'
+
'''Keyword.''' The empty value: no unit, no extra, no zone, no command, no string, an empty list.
−
    This is a null pointer.
 
  
−
  ---~---~---~---~---~---~---~---~---
+
  null
−
<span id="null"></span>
 
−
'null'
 
−
    This is a null pointer.
 
  
−
---~---~---~---~---~---~---~---~---
+
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 <code>act(..., self, null, null, TO_ROOM)</code>.
 +
 
 +
== Notes ==
 +
* <code>u == null</code> and <code>u != null</code> work for unitptr, extraptr, zoneptr and cmdptr. Many functions return null when they find nothing: findunit(), findroom(), findsymbolic(), load(), and <code>"name" in u.extra</code>.
 +
* <code>if (u)</code> and <code>while (u)</code> also test for null.
 +
* Assigning null empties a variable of any pointer, string or list type: <code>u := null;</code>, <code>s := null;</code>, <code>sl := null;</code>. 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 <code>s := "";</code>, <code>s == null</code> is false. Test strings with <code>s == ""</code>, which is true in both cases.
 +
* A field of null fails, and a failed value is false in every comparison: when <code>u</code> is null, <code>u.level > 5</code> and <code>u.level <= 5</code> are both false. <code>and</code> and <code>or</code> evaluate both sides, so test <code>if (u == null)</code> on its own before using <code>u</code>.
 +
 
 +
== Example ==
 +
<pre>
 +
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
 +
</pre>
 +
Tells whether a player carries or wears a unit, by its symbolic name (<code>"key@zone"</code>); a null player gives FALSE.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/unitptr|unitptr]]
 +
* [[Manual:DIL Manual/extraptr|extraptr]]
 +
* [[Manual:DIL Manual/string|string]]
 +
* [[Manual:DIL Manual/findsymbolic()|findsymbolic()]]
 +
* [[Manual:DIL Manual/Operators|Operators]]

Latest revision as of 23:18, 14 November 2026

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