GenerateKey

From Second Life Wiki

Jump to: navigation, search

Template:Needs Translation/LSL/de Template:Needs Translation/LSL/es Template:Needs Translation/LSL/el Template:Needs Translation/LSL/fr Template:Needs Translation/LSL/he Template:Needs Translation/LSL/it Template:Needs Translation/LSL/ja Template:Needs Translation/LSL/ko Template:Needs Translation/LSL/nl Template:Needs Translation/LSL/hu Template:Needs Translation/LSL/no Template:Needs Translation/LSL/da Template:Needs Translation/LSL/sv Template:Needs Translation/LSL/tr Template:Needs Translation/LSL/pl Template:Needs Translation/LSL/pt Template:Needs Translation/LSL/ru Template:Needs Translation/LSL/uk Template:Needs Translation/LSL/zh-Hans Template:Needs Translation/LSL/zh-Hant

Contents

Summary

Function: key generateKey( string service, string variable );

Generates a key using Type 3 (MD5) UUID generation to create a unique key using region-name, object-key, service and variable.
Returns a key The generated key

• string service The service, object, function, or whatever else this key may represent.
• string variable Any variable(s) relevant to the service that uniquely distinguish it.

Examples

In a two-prim linked-set put the following script (adding generateKey where noted) into the child-prim:

integer requestID = 0;
 
// Add generateKey here!!
 
default {
    touch_start(integer x) {
        llMessageLinked(
            LINK_ROOT, 
            1234, 
            "I am a request", 
            generateKey("echo", (string)requestID++)
        );
    }
 
    link_message(integer x, integer y, string msg, key id) {
        if (y == 1234) 
            llOwnerSay("Request: " + (string)id + " = " + msg);
    }
}
And the following script in the root-prim:
default {
    link_message(integer x, integer y, string msg, key id) {
        if (y == 1234) // Echo, send straight back
            llMessageLinked(x, y, msg, id);
    }
}
Simply touch the child-prim to use, enjoy!

Deep Notes

Implementation

key generateKey(string service, string variable) {
    return (key)llInsertString(
        llInsertString(
            llInsertString(
                llInsertString(
                    llMD5String(
                        "secondlife://" + llGetRegionName()  + "/" + 
                            (string)llGetKey() + "/" + 
                            (string)llGetLinkNumber() + "/" + 
                            llGetScriptName() + "/" + 
                            service + "/" + variable, 
                        0 // This is reserved by specification, will 
                          // be increased with new/different versions.
                    ),
                    8,
                    "-"
                ),
                13,
                "-"
            ),
            18,
            "-"
        ),
        23,
        "-"
    );
}

Optimisation

Instead of always calling llGetRegionName(), llGetKey(), llGetLinkNumber(), and llGetScriptName(), you may wish to cache their return values into a uri variable, and only dynamically add the service and variable parameters each-time. Remember to update this variable when you know it's components will have changed, using the changed(), on_rez(), and/or attach() events.

Personal tools
In other languages