Difference between revisions of "LlGetOwner"

From Second Life Wiki
Jump to navigation Jump to search
Line 46: Line 46:
The "changed" option is good when programming animations.  Since the animation system requires the owner to grant permission for the animations to act, you don't want to reset the script every time the animation device is worn.  You want to grant permissions once, and have the item work after that.  Thus, you use the "changed" event, which will reset the script once.
The "changed" option is good when programming animations.  Since the animation system requires the owner to grant permission for the animations to act, you don't want to reset the script every time the animation device is worn.  You want to grant permissions once, and have the item work after that.  Thus, you use the "changed" event, which will reset the script once.


The on_rez event is used when it is desirable to reset the script every time the object is rezzed or worn.  Both events will insure that all following script funtions will refer to the current owner.
The on_rez event is used when it is desirable to reset the script every time the object is rezzed or worn.   
 
Both events will insure that all following script funtions will refer to the current owner.


|helpers
|helpers

Revision as of 07:42, 25 February 2008

Summary

Function: key llGetOwner( );
0.0 Forced Delay
10.0 Energy

Returns a key that is the current owner of the script.

(See additional ErenNotes at end of this listing)

Caveats

  • When the owner of an object changes, code that depends on this function's return value will not automatically update for the new owner or be automatically re-evaluated.
    • This requires the reregistration of listens and requesting of permissions from the new owner as needed.
      • This is not limited to listens and permissions but anything that caches the return value, it is up to the programmer to work around this limitation.
    • Detection of owner change can be achieved with the changed event in conjunction with the CHANGED_OWNER flag (see the first example) or by storing the old value and periodically (e.g. in on_rez) checking if it has changed. Both techniques are valid though the latter will not detect the sale of the object if it is sold with "sell original" in-world and not picked up.

Examples

<lsl>default {

   state_entry()
   {
       llInstantMessage(llGetOwner(), "Only you can hear me. Isn't that eerie.");
   }
   changed(integer change)
   {
       if (change & CHANGED_OWNER)
           llResetScript();
   }

}</lsl>

ErenNotes (the "Scripting for Dummies" section)

llGetOwner() returns the UUID (identification code) of the owner of the object.

To get the owner's name, use llKey2Name(llGetOwner())

<lsl>Examples: llSay(0,(string)llGetOwner()); // speaks in chat the "key" (UUID code) of the avatar. llSay(0,llKey2Name(llGetOwner())); // speaks in chat the name of the avatar.</lsl>

The one problem many coders come up against is that previously-activated events referring to the owner don't automatically change when the owner changes. The most often-seen result is an animation function affecting the PREVIOUS owner rather than the CURRENT owner. While this initially seems a "bug" in the llGetOwner() function, it is not. What happens is that no event has happened to cause the code to recognize a new owner. There are two simple one-line solutions to this problem. Both solutions cause the script to reset all values.

<lsl>changed(integer change){if (change & CHANGED_OWNER)llResetScript();} //if owner changes, reset the script. Resets script once.

on_rez(integer start_param){llResetScript();} //when object rezzes, reset the script. Resets the script every time object is rezzed.</lsl>

The "changed" option is good when programming animations. Since the animation system requires the owner to grant permission for the animations to act, you don't want to reset the script every time the animation device is worn. You want to grant permissions once, and have the item work after that. Thus, you use the "changed" event, which will reset the script once.

The on_rez event is used when it is desirable to reset the script every time the object is rezzed or worn.

Both events will insure that all following script funtions will refer to the current owner.

See Also

Functions

•  llGetCreator
•  llGetOwnerKey
•  llDetectedOwner

Deep Notes

Signature

function key llGetOwner();