The key type is a specialized string, a unique identifier that can be used to reference objects, inventory items and agents in Second Life.
Sometimes also referred to as UUID (Universal Unique IDentifier), UID, or asset-ID, a key can be represented as a string of hexadecimal numbers in the format “00000000-0000-0000-0000-000000000000” (for example “66864f3c-e095-d9c8-058d-d6575e6ed1b8”). A key is 36 characters long when converted to a string in LSL (32 hexadecimal digits + 4 dashes).
There are 2^128 possible key combinations, yielding 340,282,366,920,938,463,463,374,607,431,768,211,456 possible keys. Because of this, there is little worry over SL running out of keys for objects, scripts, sounds, and textures.
Because a key is really just a specialized string, any string can be stored into a key variable, though it shouldn’t be expected to work in a function that needs a UUID if the key variable contains “Hello”. Note that keys must be explicitly typecast to strings, even though they are implicitly typecast from strings. If data needs to be typecast from any other type to a key, it must first be cast to a string.
That being said, if a UUID is not needed to be passed in a llMessageLinked call, a second string can be passed as long as it is cast as a key and then recast back to a string in the receiving link_message event.
Example:
llMessageLinked(LINK_SET, 5, "String one", (key)"String two");
This hack can be pretty useful, but keep in mind that you’re relying on things that might change at any time when using it.
Note that in some cases, you don’t need to explicitly state (string)keyname as you do when converting between a string and an integer, for instance. It’s good coding practice to always do so, however, as many functions will not work properly unless you do.
integer isKey(key in) {//by: Strife Onizuka if(in) return 2; // key is valid AND not equal NULL_KEY; the distinction is important in some cases (return value of 2 is still evaluated as unary boolean TRUE) return (in == NULL_KEY); // key is valid AND equal to NULL_KEY (return 1 or TRUE), or is not valid (return 0 or FALSE) } key forceKey(key in) {//force a string or key to be a valid key assuming you want invalids to become NULL_KEY if(in) return in; return NULL_KEY; }
Note: Some keys change under certain circumstances, while others can be trusted to NEVER change. The following Table illustrates which keys can be trusted and which may change.
Key Type | Changes? | When it changes |
Agent | NO | Never Changes |
Animation | NO | Never Changes |
Notecard | YES | When Edited or Saved |
Object | YES | Rezzed |
Object (attached) | YES | Avatar object is attached to logs in or teleports |
Script | YES | Any time a change or new copy is made |
Sound | NO | Never Changes |
Texture | NO | Never Changes |
Anyone want to contribute to this table, correct mistakes, or add more Types?
Function | Purpose |
llDetectedKey | returns the key of detected object |
llGetKey | returns the key of the object the script is in |
llGetInventoryKey | returns an object inventory item key |
llGetOwnerKey | returns the key of the owner of the object who’s key was passed to the function |
llGetOwner | returns the key of the script owner |
llKey2Name | converts a key to a name (in-sim only) |
See Client Asset Keys for default assets like textures (GUI, “missing”, terrain, etc), animations, sounds, etc.