Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

object ownership initialization

robin Meridoc
Registered User
Join date: 9 Jan 2009
Posts: 7
06-06-2009 13:11
Let's say I've created an object, it has one or more scripts in it. In that object, in state_entry() I say.....

key id = llGetOwner();
string name = llKe2Name( id );

Further down in the object, in one of the other scripts, I do some llDialog work too.

Now - I give a copy of the object to a friend and she gives it a try. To my astonishment, I get the menu's I intended for her to get. Clearly I need some initialization help here. Can anyone tell me why isn't the new owner of the object being picked up by state_entry()? And what I should be using in addition or instead?

The object in question is intended to be worn as a hud, if it makes a difference. And if it does, what should be done in other cases?

Thanks,
Robin
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
06-06-2009 13:18
From: robin Meridoc
Let's say I've created an object, it has one or more scripts in it. In that object, in state_entry() I say.....

key id = llGetOwner();
string name = llKe2Name( id );

Further down in the object, in one of the other scripts, I do some llDialog work too.

Now - I give a copy of the object to a friend and she gives it a try. To my astonishment, I get the menu's I intended for her to get. Clearly I need some initialization help here. Can anyone tell me why isn't the new owner of the object being picked up by state_entry()? And what I should be using in addition or instead?

The object in question is intended to be worn as a hud, if it makes a difference. And if it does, what should be done in other cases?

Thanks,
Robin


A script remains in its running state unless stopped or reset. Taking it into inventory merely suspends the running state. If you make a copy, BOTH copies have the script still running. The object may have changed owners, but the script doesn;t know that. If you want the script to know that ownership has changed, put a changed event in the script, test for CHANGE_OWNER, and then llResetScript.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
robin Meridoc
Registered User
Join date: 9 Jan 2009
Posts: 7
06-06-2009 13:34
Thanks so much!

If I have more than one script in an object, I guess need to add the changed event and llResetScript() to each. Or is there a reason to not do so?

robin
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
06-06-2009 15:18
Good plan. While you're at it, be sure that you also have a changed event in each state of a script (if it has more than one state).

CODE

changed(integer change)
{
if (change & CHANGED_OWNER)
{
llResetScript();
}
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
06-06-2009 16:33
From: robin Meridoc
Thanks so much!

If I have more than one script in an object, I guess need to add the changed event and llResetScript() to each. Or is there a reason to not do so?

robin

there are several reasons why you may not want to reset a script, including preserving current script state, and variable contents, like configuration settings.

in most cases the only reason to reset on owner change is because some initialization data depended on the owner, and once that changed it needed to be updated (command listens are a common example).

it is possible to code around these needed updates without destroying current data, by either putting you initilizing functions that depend on the owner into
A) their own state, and calling that state on change, which afterward forwards to the working state
B) their own function, called from state entry and the changed events

if you are just storing the owners key for comparison references, it's smaller (though not necessarily faster) in most cases to just use the built in llGetOwner() call which will be current every time you call it.

the state method is god if you're canceling old listens and installing new ones (because listens are canceled when you change states), and the function method is probably preferable in most other cases.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
Tip: on_rez, to llResetScript or not to llResetScript
06-07-2009 03:24
_____________________
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
06-07-2009 05:04
Void has right you dont need to reset the script if you have some important data in there , just use another state keeping the esential data in teh first state or make the getOwner call again in your changed owner .

From: someone

//if you make your variables as globals , they can be accessed any time and change their values


key id;
string name;

//get the first time the values as normal and then if some owner chaged happend trigger the get owner again

// some code here

changed(integer change)
{
if (change & CHANGED_OWNER)
{
id = llGetOwner();
name = llKe2Name( id );
}
}

//some code here too
_____________________


RAW terrain files - terraform your SIM!!
http://www.wishland.info/
PD:the wiki its your friend ;)
http://wiki.secondlife.com/wiki/LSL_Portal
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
06-07-2009 05:50
oh, and as a fun "abuse the system" trick...

a common method for providing multiple listens that cancel after a timeout (think multiple users and dialogs) it's often easier to to just jump to an empty state and back, then to track them. (which cancels ALL open listens).

the fun part is if you have special owner only functions/responses defined based on llGetOwner, instead of resetting, or even updating the listen in the changed event, simply force a normal listen timeout, and restart your owner listen as normal =)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -