Difference between revisions of "LlGetOwner"

From Second Life Wiki
Jump to navigation Jump to search
Line 6: Line 6:
|func_desc
|func_desc
|return_text=that is the current owner of the script.
|return_text=that is the current owner of the script.
(See additional ErenNotes at end of this listing)
|spec
|spec
|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.
|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.
Line 25: Line 27:
     }
     }
}</lsl>
}</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())
The one problem many coders come up against is that statements referring to the owner don't automatically change when the owner changes.  The most often-seen result is an expected animation command 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 real-time 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.
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.
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.
|helpers
|helpers
|also_functions=
|also_functions=

Revision as of 08:29, 25 February 2008

Summary

Function: key llGetOwner( );

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.
All Issues ~ Search JIRA for related Bugs

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())

The one problem many coders come up against is that statements referring to the owner don't automatically change when the owner changes. The most often-seen result is an expected animation command 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 real-time 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.

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.

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

Search JIRA for related Issues

Signature

function key llGetOwner();