Don't click here unless you want to be banned.

LSL Wiki : key

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are


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.

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.

Types | Client Asset Keys | Memory Usages
Comments [Hide comments/form]
The older keychecker sucked, so I rewrote it. This one has multi-letter variable names!
-- KeknehvPsaltery (2005-07-05 12:33:57)
LEAVE IT ALONE ICE! Your stupid capitalized titles are there but the LINKS are lowercase!!!!!!!! Damn vulture...
-- EepQuirk (2005-08-24 11:29:12)
/me waves fist at Keknehv "if it weren't for you pesky kids i would have gotten away with it"
haha thx for the fix, sometime i get a bit carried away.

Eep, chill
-- BlindWanderer (2005-08-24 13:17:05)
Eep, that's... rather hypocritical for someone who yells about strict users on a Wiki, also have you unlocked your page's ACLs yet?
-- IceBrodie (2005-08-25 01:36:44)
I won't chill until you and others stop screwing with the damn case. What's the big deal? Do you idiots LIKE to be inefficient, redundant, and wasteful? Jesus Christ! And why the hell would I bother unlocking my page ACLs when you twits will just screw them up again?
-- EepQuirk (2005-08-25 03:57:31)
Erm... we kinda do, as there is a lot of information and bridging that information makes it harder to reference.
-- IceBrodie (2005-08-25 06:51:57)
Eep is actually right! We're all vultures and trollers! Shame on us for trying to change things! He is doing us all a favor by protecting his valuable knowledge from destruction at our hands...
-- KeknehvPsaltery (2005-08-25 13:17:52)
Ah... interesting. I see what you're doing. I was wondering if there was a way to do that. Let me try to make that just a bit faster.

**Several minutes later**

You had a few bugs in your function... But I improved upon it a bit, I think.

integer isKey(key test) 
    if (llStringLength(test) != 36)
        return FALSE;

    // Hyphenation test:
    if  (     (llGetSubString(test, 8, 8) != "-")
          ||  (llGetSubString(test, 13, 13) != "-")
          ||  (llGetSubString(test, 18, 18) != "-")
          ||  (llGetSubString(test, 23, 23) != "-"))
            return FALSE;
    // Remove dashes
    test = llDeleteSubString(llDeleteSubString(llDeleteSubString(llDeleteSubString((string)test, 8, 8), 12, 12), 16, 16), 20, 20);
    // Hex test
    integer i;
    for (i = 0; i < 32; i+=4) 
        string char = llGetSubString(test, i, i+3 );
        if ((integer)("0x"+char) == 0 && char != "0000") 
            return FALSE;
    return TRUE; // Passed all tests

Now it processes in 64-bit segments.
-- KeknehvPsaltery (2005-08-25 16:21:35)
I thought something like that would be a good way to speed things up, to process the string in 8-char hex strings (max int). However, if the integer typecast parser encounters something like "0xFGD", it returns 15 (I think) - it chokes on the "G" and spits out what it accumulated beforehand. The reason I had all the llGetSubStrings as seperate conditional statements was due to LSL's inability to short-circuit; all four of those llGetSubStrings are executed before the VM makes a decision.
integer i;
for (i = 0; i < 32; i+=4) 
    string char = llGetSubString(test, i, i+3 );
    if ((integer)("0x"+char) == 0 && char != "0000") 
        return FALSE;
-- ChristopherOmega (2005-08-25 21:39:30)
Why are you removing keys, Ice?? LEAVE IT THERE! God damn vulture...
-- EepQuirk (2005-08-26 20:01:17)
Should anyone not good with math be curious just how many keys 3.40E+44 really is let me give some detail.
3.40E+44 would normally be said as "3.4 times 10 to the 44th power" or written as 34,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
(You could also call this 34 Quattuordecillion (Pronounced quat'tu·or·di·cil'lion)). Which is roughly the number of atoms in 1/4 of the earths water, or 1/3 the area in square miles of a slice through the center of the universe.

Thats BIG folks :)
-- LasivianLeandros (2005-09-05 09:38:46)
Oops - what I posted had some compilation errors, here's a revised version:
integer isKey(key test) {
    if (llStringLength(test) != 36)
        return FALSE;
    // Hyphenation tests:
    if (llGetSubString(test, 8, 8) != "-")
        return FALSE;
    if (llGetSubString(test, 13, 13) != "-")
        return FALSE;
    if (llGetSubString(test, 18, 18) != "-")
        return FALSE;
    if (llGetSubString(test, 23, 23) != "-")
        return FALSE;
    // Hex test:
    // Remove dashes (fixed, thanks Kek :-))
    test = llDeleteSubString(llDeleteSubString(llDeleteSubString(llDeleteSubString((string)test, 23, 23), 18, 18), 13, 13), 8, 8);
    integer i;
    for (i = 0; i < 32; ++i) {
        string char = llGetSubString(test, i, i);
        if ((integer)("0x"+char) == 0 && char != "0") {
            return FALSE;
    return TRUE; // Passed all tests:
-- ChristopherOmega (2005-11-29 22:03:46)
Is it possible to get the key of another avitar, but not asking them?
-- ZackyCommons (2006-06-13 17:35:50)
Yes, by using the llDetectedKey() function.
-- PattehFox (2006-09-05 11:31:57)
you key changes when you become a linden, you loose your key=P
-- Bobbyb30 (2007-04-07 15:33:39)
Bobby is that a joke or is it for real? if so, do you have any sources to back that claim?
-- TigroSpottystripesKatsu (2007-10-23 17:49:16)
Edited function table - descriptions for llGetOwner() and llGetOwnerKey() were the wrong way around
-- PeterCanessaOh (2007-12-03 05:48:32)
@TigroSpottystripesKatsu, When you become a linden your key is changed and hidden. You can prove this by attempting to find the birthdate of a former nonlinden with their old key and you will find its missing. Also, a linden's key cannot be traced. When you attempt to find their key, it returns NULL_KEY.
-- Bobbyb30Zohari (2007-12-04 14:52:35)
A Linden's key is only hidden when they are in God Mode(In God Mode, they are no longer an agent), otherwise you can get thier key and use it. I just ran a check in world and was able to see that Cogsworth Linden was online by looking in group and by checking the status with llRequestAgentData(keyname, DATA_ONLINE); It returned TRUE.
-- (2007-12-10 19:16:12)
Attach a comment to this page: