Difference between revisions of "LlGenerateKey"

From Second Life Wiki
Jump to navigation Jump to search
m (added example)
Line 8: Line 8:
*As the UUID produced is versioned, it should never return a value of [[NULL_KEY]].
*As the UUID produced is versioned, it should never return a value of [[NULL_KEY]].
|mode
|mode
|examples
|examples=
<lsl>
default
{
    touch_start(integer num_detected)
    {
        // avatar touching
        key avatarKey = llDetectedKey(0);
        string avatarName = llKey2Name(avatarKey);
 
        // key of the owner
        key owner = llGetOwner();
 
        // generated random key
        key random = llGenerateKey();
 
        // number of objects inside the same prim
        integer numberOfObjects = llGetInventoryNumber(INVENTORY_OBJECT);
 
        if (numberOfObjects)
        {
            // name of first object sorted by name inside the prim's inventory
            string itemName = llGetInventoryName(INVENTORY_OBJECT, 0);
   
            llGiveInventory(avatarKey, itemName);
            llInstantMessage(avatarKey, "Your transaction key is '" + (string)random + "'.");
   
            llInstantMessage(owner, "Transaction record:\n"
                + "receiver: " + avatarName + " (" + (string)avatarKey + ")\n"
                + "item: " + itemName + "\n"
                + "transaction key: " + (string)random);
        }
        else
        {
            // PUBLIC_CHANNEL has the integer value 0
            llSay(PUBLIC_CHANNEL, "No items to give away, sorry!");
        }
    }
}
</lsl>
|cat1=Key
|cat1=Key
|cat2
|cat2

Revision as of 11:17, 5 October 2012

Summary

Function: key llGenerateKey( );

Generates a key using Version 5 (SHA-1 hash) UUID generation to create a unique key.
Returns the key generated.

Caveats

  • The specific UUID version is an implementation detail that has changed in the past and may change again in the future. Do not depend upon the UUID that is returned to be Version 5.
  • As the UUID produced is versioned, it should never return a value of NULL_KEY.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> default {

   touch_start(integer num_detected)
   {
       // avatar touching
       key avatarKey = llDetectedKey(0);
       string avatarName = llKey2Name(avatarKey);
       // key of the owner
       key owner = llGetOwner();
       // generated random key
       key random = llGenerateKey();
       // number of objects inside the same prim
       integer numberOfObjects = llGetInventoryNumber(INVENTORY_OBJECT);
       if (numberOfObjects)
       {
           // name of first object sorted by name inside the prim's inventory
           string itemName = llGetInventoryName(INVENTORY_OBJECT, 0);
   
           llGiveInventory(avatarKey, itemName);
           llInstantMessage(avatarKey, "Your transaction key is '" + (string)random + "'.");
   
           llInstantMessage(owner, "Transaction record:\n"
               + "receiver: " + avatarName + " (" + (string)avatarKey + ")\n"
               + "item: " + itemName + "\n"
               + "transaction key: " + (string)random);
       }
       else
       {
           // PUBLIC_CHANNEL has the integer value 0
           llSay(PUBLIC_CHANNEL, "No items to give away, sorry!");
       }
   }

}

</lsl>

Deep Notes

History

Search JIRA for related Issues

Signature

function key llGenerateKey();