How can I kill just a child object?
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
05-17-2005 08:58
Hello there,
Suppose, there are three linked objects, A, B, and C. A is the root. And I'd like to kill just C. So I set llMessageLinked and intend to make C llDie. But I realized that all objects would also die when C died. Do I need llBreakLink first? But how can I direct only C to unlink? Of course, I can't unlink all objects.
Please help.
_____________________
 Seagel Neville 
|
|
Jon Marlin
Builder, Coder, RL & SL
Join date: 10 Mar 2005
Posts: 297
|
05-17-2005 10:33
From: Seagel Neville Hello there,
Suppose, there are three linked objects, A, B, and C. A is the root. And I'd like to kill just C. So I set llMessageLinked and intend to make C llDie. But I realized that all objects would also die when C died. Do I need llBreakLink first? But how can I direct only C to unlink? Of course, I can't unlink all objects.
Please help. The wiki generally answers questions like this: http://secondlife.com/badgeo/wakka.php?wakka=llBreakLinkThere's an example of exactly what you're asking for on that page. You can get C's link number by having it ask - llGetLinkNumber (). It can pass that info to a root prim script in a linked message. When appropriate, the root prim script can call llBreakLink with C's link number. C will have the piece of the script from the above wiki page, and it will kill itself after it is de-linked. Beware though, if the script is active, and you unlink the objects in the editor, that code will run, and your C object will disappear. You will need to remember to turn off the script in C before you manually de-link the object. - Jon
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
05-17-2005 20:59
Hello Jon, From: Jon Marlin You can get C's link number by having it ask - llGetLinkNumber (). It can pass that info to a root prim script in a linked message. When appropriate, the root prim script can call llBreakLink with C's link number. Thank you. I got it. Object C: llMessageLinked(llGetLinkNumber();, 0, "unlink me", "") Object A(root): link_message(integer sender_num, integer num, string str, key id) { If (str == "unlink me") { llRequestPermissions(PERMISSION_CHANGE_LINKS); llBreakLink(sender_num); } } Like this? Thank you. I'll try this after coming home. 
_____________________
 Seagel Neville 
|
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
05-17-2005 21:25
From: Seagel Neville Hello Jon, Object A(root): link_message(integer sender_num, integer num, string str, key id) { If (str == "unlink me") { llRequestPermissions(PERMISSION_CHANGE_LINKS); llBreakLink(sender_num); } } Like this? Thank you. I'll try this after coming home.  Not quite, it would make more sence to have the root object ask you for permissions a while before the llBreakLink call. Mainly because you actually have to be there to grant the CHANGE_LINKS permission. If you want the object to be autonomas (sp?) its best to ask permissions beforehand. Try this: // Script is in this state when it first starts up. default { state_entry() { llOwnerSay("Please grant permission to link."); llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS); } run_time_permissions(integer perms) { if (perms & PERMISSION_CHANGE_LINKS) // If permission granted: { state ready; } else { llOwnerSay("I need linking permission to function correctly."); llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS); } } link_message(integer sender_num, integer num, string str, key id) { if (str == "unlink me") { // Send error message? // Script can't unlink stuff! } }
} // Script is in this state when everything's // running smoothly - it has permissions. state ready { run_time_permissions(integer perms) { if (!(perms & PERMISSION_CHANGE_LINKS)) // If permissions revoked { // This technically shouldn't happen, but just in case. state default; } } link_message(integer sender_num, integer num, string str, key id) { if (str == "unlink me") { // Check permissions beforehand, so object doesn't spam. if (llGetPermissions() & PERMISSION_CHANGE_LINKS) { llBreakLink(sender_num); } else { // Send error message? // Script can't unlink stuff! state default; } } } }
|
|
Ushuaia Tokugawa
Nobody of Consequence
Join date: 22 Mar 2005
Posts: 268
|
05-17-2005 22:00
Chris was quicker at the draw than me, but if it's not too presumptuous may I offer a small improvement to his already excellent suggestion. If this object is sold or given to somebody else, the new owner won't get the permission request until the link message is sent (unless you take the object into inventory while it's in the default state). At that point, they might not be in a position to grant the permissions. Therefore, I suggest adding an additional permission test to on_rez in the ready state as such: on_rez(integer start_param) { if (!(llGetPermissions() & PERMISSION_CHANGE_LINKS)) state default; }
While I realize Chris was already very dilligent with his permission tests, this addition will make transferring the object even easier on you. Also, here is a small script to place inside the child prim so that it will die when it is unlinked: default { changed(integer change) { if (change & CHANGED_LINK) { if (llGetLinkNumber() == 0) { llDie(); } } } }
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
05-17-2005 22:31
 I got it's really serious to break the link. Thank you, Christopher and Ushuaia. I realized that I should put down my script here anyway.
_____________________
 Seagel Neville 
|
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
05-17-2005 22:36
From: Ushuaia Tokugawa Therefore, I suggest adding an additional permission test to on_rez in the ready state as such: on_rez(integer start_param) { if (!(llGetPermissions() & PERMISSION_CHANGE_LINKS)) state default; }
Oops! Missed that, thanks for the correction There might still be a problem, even with your correction, though. What if the object retains permissions from its previous owner? (Im not sure if permissions are retained when objects are sold) In that case, you might want to do this also: on_rez(integer start_param) { if (!(llGetPermissions() & PERMISSION_CHANGE_LINKS) || llGetPermissionsKey() != llGetOwner()) state default; }
Ah, the loops we have to run through just for permission to do stuff  ==Chris
|
|
Sean Martin
Yesnomaybe.
Join date: 13 Sep 2005
Posts: 584
|
02-17-2006 14:17
Is there a way to kill unlinked objects that were never linked in the first place? Maybe search for a prim in a local area when something like "kill objects" is said. Then have a remote search for the name of the object and kill it so long as it is the owners prim? I need something like this so I don't have listen scripts in each prim that is not linked. And they must stay unlinked I hope there is a way around that.
|
|
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
|
02-17-2006 16:04
From: Sean Martin Is there a way to kill unlinked objects that were never linked in the first place? Maybe search for a prim in a local area when something like "kill objects" is said. Then have a remote search for the name of the object and kill it so long as it is the owners prim? I need something like this so I don't have listen scripts in each prim that is not linked. And they must stay unlinked I hope there is a way around that. No, only scripts within an object can cause them to die.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
02-17-2006 16:55
If you already have a script in there, and that script has a listener, you could modify the script to make it kill itself when it hears a specific command.
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
02-17-2006 17:43
 This is the thread that I began a long time ago. Ziggy, what Catherine said. If the child prim died, the whole object would... 
_____________________
 Seagel Neville 
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
02-17-2006 17:49
Sorry. I was replying to Sean's question, where it sounded like he was starting with unlinked prims/objects.
|
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
02-17-2006 18:03
Yes, you were. 
_____________________
 Seagel Neville 
|