NULL KEY: Difference between revisions

From Second Life Wiki
Jump to navigation Jump to search
Strife Onizuka (talk | contribs)
No edit summary
Wulfie Reanimator (talk | contribs)
mNo edit summary
 
(8 intermediate revisions by 4 users not shown)
Line 3: Line 3:
|type=string
|type=string
|value="00000000-0000-0000-0000-000000000000"
|value="00000000-0000-0000-0000-000000000000"
|desc={{BlinkText|style=color:red;|'''NULL_KEY is a [[string]].'''}} However it is only really useful as a [[key]].
|desc=<span style="color:red;">'''NULL_KEY is a [[string]].'''</span> However it is only really useful as a [[key]].


Despite fitting the syntax criteria to be a valid [[key]], when fed to a {{LSLGC|Conditional}} as a key it executes as [[FALSE]].
For {{LSLGC|Conditional}} tests, NULL_KEY evaluates to '''TRUE''' like other strings.
 
For list search (like [[llListFindList]]), NULL_KEY won't match null keys whose type is '''key''' without typecasting.
|examples=
|examples=
<lsl>integer isKey(key in) {
<source lang="lsl2">
     if(in) return 2;
// Returns 2 for valid keys, 1 for NULL_KEY, 0 for invalid keys.
     return (in == NULL_KEY);
integer isKey(key input)
}//returns 2 if it's a valid key, 1 if it's NULL_KEY</lsl>
{
<lsl>// NULL_KEY itself is evaluated as FALSE only when it is casted as a key.
     if (input) return 2;
default {
     return (input == NULL_KEY);
    state_entry() {
}
         if (NULL_KEY) { llOwnerSay("NULL_KEY is TRUE");  }// Correct.
</source>
         else          { llOwnerSay("NULL_KEY is FALSE"); }// Never.
<source lang="lsl2">
       
default
         if ((key) NULL_KEY) { llOwnerSay("Casted NULL_KEY is TRUE");  }// Never.
{
         else                { llOwnerSay("Casted NULL_KEY is FALSE"); }// Correct.
    state_entry()
    {
        // NULL_KEY itself is evaluated as FALSE only when typecast to key.
         if (NULL_KEY) { llOwnerSay("NULL_KEY is TRUE");  } // Correct.
         else          { llOwnerSay("NULL_KEY is FALSE"); } // Never.
 
         if ((key) NULL_KEY) { llOwnerSay("Casted NULL_KEY is TRUE");  } // Never.
         else                { llOwnerSay("Casted NULL_KEY is FALSE"); } // Correct.
 
        // NULL_KEY won't match keys in lists without typecasting.
        // The following list contains a null key because avatars don't have creators:
        list details = llGetObjectDetails(llGetOwner(), [OBJECT_CREATOR]);
        integer index = llListFindList(details, [NULL_KEY]);
        if (index >= 0) { llOwnerSay("NULL_KEY was found in list"); } // Never.
        else            { llOwnerSay("NULL_KEY was NOT found in list"); } // Correct.
     }
     }
}</lsl>
}
</source>
|notes=In most situations NULL_KEY isn't needed; an empty string ("") will suffice. To take advantage of this certain practices have to be avoided. In many applications keys are checked against NULL_KEY to determine if they are valid; this is bad practice.
|notes=In most situations NULL_KEY isn't needed; an empty string ("") will suffice. To take advantage of this certain practices have to be avoided. In many applications keys are checked against NULL_KEY to determine if they are valid; this is bad practice.


Line 36: Line 53:
|events=
|events=
{{LSL DefineRow||[[attach]]|}}
{{LSL DefineRow||[[attach]]|}}
|haiku={{Haiku|My hopes for nothing|but for thirty two zeros,|have been dashed, four times.}}
|cat1=Key
|cat1=Key
|cat2
|cat2

Latest revision as of 10:10, 18 October 2025

Description

Constant: string NULL_KEY = "00000000-0000-0000-0000-000000000000";

The string constant NULL_KEY has the value "00000000-0000-0000-0000-000000000000"

NULL_KEY is a string. However it is only really useful as a key.

For Conditional tests, NULL_KEY evaluates to TRUE like other strings.

For list search (like llListFindList), NULL_KEY won't match null keys whose type is key without typecasting.

Caveats


Related Articles

Functions

•  llAvatarOnSitTarget
•  llDetectedKey
•  llGetNotecardLine
•  llGetLandOwnerAt
•  llGetPermissionsKey
•  llGetTexture
•  llListen

Events

•  attach

Examples

// Returns 2 for valid keys, 1 for NULL_KEY, 0 for invalid keys.
integer isKey(key input)
{
    if (input) return 2;
    return (input == NULL_KEY);
}
default
{
    state_entry()
    {
        // NULL_KEY itself is evaluated as FALSE only when typecast to key.
        if (NULL_KEY) { llOwnerSay("NULL_KEY is TRUE");  } // Correct.
        else          { llOwnerSay("NULL_KEY is FALSE"); } // Never.

        if ((key) NULL_KEY) { llOwnerSay("Casted NULL_KEY is TRUE");  } // Never.
        else                { llOwnerSay("Casted NULL_KEY is FALSE"); } // Correct.

        // NULL_KEY won't match keys in lists without typecasting.
        // The following list contains a null key because avatars don't have creators:
        list details = llGetObjectDetails(llGetOwner(), [OBJECT_CREATOR]);
        integer index = llListFindList(details, [NULL_KEY]);
        if (index >= 0) { llOwnerSay("NULL_KEY was found in list"); } // Never.
        else             { llOwnerSay("NULL_KEY was NOT found in list"); } // Correct.
    }
}

Notes

Like any LSO string constants longer then 3 characters and used in multiple places in the code, they should be stored in a global variable. The result will be a considerable memory savings. This does not apply to scripts compiled with Mono. See LSL Constants vs Globals for more information about this and examples.
In most situations NULL_KEY isn't needed; an empty string ("") will suffice. To take advantage of this certain practices have to be avoided. In many applications keys are checked against NULL_KEY to determine if they are valid; this is bad practice.

LSL makes it easy to check if a key is valid. Simply use the key as the parameter for a conditional.

That is, instead of if(uuid != NULL_KEY), use if(uuid). if(uuid) will only return TRUE if it is a valid key that is also not a null key.

Deep Notes

All Issues

~ Search JIRA for related Issues
   NULL_KEY is no longer a NULL_KEY when passed to a function

Signature

string NULL_KEY = "00000000-0000-0000-0000-000000000000";

Haiku

My hopes for nothing
but for thirty two zeros,
have been dashed, four times.