Difference between revisions of "NULL KEY"
Line 8: | Line 8: | ||
Some people say that in most applications NULL_KEY isn't needed, and that an empty string ( "" ) will suffice. Others say that doing so is bad style, can cause hard-to-track-down bugs in your script, and might be unsupported in future code releases. | Some people say that in most applications NULL_KEY isn't needed, and that an empty string ( "" ) will suffice. Others say that doing so is bad style, can cause hard-to-track-down bugs in your script, and might be unsupported in future code releases. | ||
Not that that NULL_KEY does not actually equal "". | |||
See this example: | |||
key tmp = "";<br /> | |||
if (tmp != NULL_KEY) llSay(0, "See, NULL_KEY does not equal \"\"");<br /> | |||
|examples= | |examples= | ||
Line 16: | Line 23: | ||
}//returns 2 if it's a valid key, 1 if it's NULL_KEY | }//returns 2 if it's a valid key, 1 if it's NULL_KEY | ||
</lsl> | </lsl> | ||
|notes=test | |notes=test | ||
|functions= | |functions= |
Revision as of 21:29, 7 July 2008
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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.
Some people say that in most applications NULL_KEY isn't needed, and that an empty string ( "" ) will suffice. Others say that doing so is bad style, can cause hard-to-track-down bugs in your script, and might be unsupported in future code releases.
Not that that NULL_KEY does not actually equal "".
See this example:
key tmp = "";
if (tmp != NULL_KEY) llSay(0, "See, NULL_KEY does not equal \"\"");
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.
test