Difference between revisions of "Manual:DIL Manual/null"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
| + | = 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 <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
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.