Difference between revisions of "NULL KEY"

From Second Life Wiki
Jump to navigation Jump to search
(//corrected some language, cannot find where this typo is coming from: they should be store in a)
Line 11: Line 11:
     return (in == NULL_KEY);
     return (in == NULL_KEY);
}//returns 2 if it's a valid key, 1 if it's NULL_KEY</lsl>
}//returns 2 if it's a valid key, 1 if it's NULL_KEY</lsl>
|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 and that is used to assume if they are valid; this is a bad practice. LSL makes it easy to check if a key is valid, all that is required is to use it as the parameter for a conditional. So instead of <code>if(uuid != NULL_KEY)</code> use <code>if(uuid)</code>, it will only return true if it is a valid key that is not NULL_KEY.
|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.
 
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 <code>if(uuid != NULL_KEY)</code>, use <code>if(uuid)</code>. <code>if(uuid)</code> will only return true if it is a valid key and if it is not a NULL_KEY.
|functions=
|functions=
{{LSL DefineRow||[[llAvatarOnSitTarget]]|}}
{{LSL DefineRow||[[llAvatarOnSitTarget]]|}}

Revision as of 09:33, 13 July 2008

Description

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

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

While technically a string constant, it is only useful as a key.

Despite fitting the syntax criteria to be a valid key, when fed to a Conditional as a key it executes as false.

Caveats


Related Articles

Functions

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

Events

•  attach

Examples

<lsl>integer isKey(key in) {

   if(in) return 2;
   return (in == NULL_KEY);

}//returns 2 if it's a valid key, 1 if it's NULL_KEY</lsl>

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 and if it is not a NULL_KEY.

Deep Notes

Search JIRA for related Issues

Signature

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