Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Can we linked prim using script?

et0021 Jupiter
Registered User
Join date: 28 Sep 2009
Posts: 11
12-22-2009 22:43
Hi,

Just wanne find out, can we use scripting to link prim together instead of using selection and Ctrl+L?

If possible can give me some information / advice on it or tutorial on how it can be done?

Thanks?
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
12-22-2009 22:47
Yep, see http://wiki.secondlife.com/wiki/LlCreateLink, http://wiki.secondlife.com/wiki/LlBreakLink, http://wiki.secondlife.com/wiki/LlBreakAllLinks. There are examples in there.

The same linking restrictions you get from the viewer apply.
et0021 Jupiter
Registered User
Join date: 28 Sep 2009
Posts: 11
12-27-2009 22:32
thanks for the info.

But I don't really understand the example, if possible that you can explain to me? for the code in llCreateLink

Questions:
1) Where should this code be? in the child prim or the parent prim?
2) For the "Useful Snippets" code, where should I put it?
3)"// Create a new object and link it as a child prim." - does this part mean i have to create 2 prim that is already linked together at first?
4)"// NOTE: must be a name of an object in this object's inventory." - What does it mean by this?
5) why its say?? - " // Only bother rezzing the object if will be able to link it."
6) " // This is the parent object. Create a link to the newly-created child." - What is the parent object? what is the newly-created child?

Code:

// Create a new object and link it as a child prim.
string ObjectName = "Object Name Here";
// NOTE: must be a name of an object in this object's inventory.

default
{
touch_start(integer count)
{
// When the object is touched, make sure we can do this before trying.
llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);
}
run_time_permissions(integer perm)
{
// Only bother rezzing the object if will be able to link it.
if (perm & PERMISSION_CHANGE_LINKS)
llRezObject(ObjectName, llGetPos() + <0,0,0.5>, ZERO_VECTOR, llGetRot(), 0);
else
llOwnerSay("Sorry, we can't link.";);
}
object_rez(key id)
{
// NOTE: under some conditions, this could fail to work.
// This is the parent object. Create a link to the newly-created child.
llCreateLink(id, TRUE);
}
}

Useful Snippets:

// child prim key
key kChild = NULL_KEY;
integer bLink = TRUE; // we suppose this script is on a linked object
default
{

state_entry()
{
// get the permission to change the link
llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);

// get the child key
kChild = llGetLinkKey(2);
}


touch_start(integer nTotalCliquor)
{
if (bLink)
{
// break all my links, wait 1.5 sec
llBreakAllLinks();
llSleep(1.5);

// i'm unlinked
llSay(0, "Unlinked, click to link";);
bLink = FALSE;
}
else
{
// redo my link
llCreateLink(kChild, TRUE);
llSleep(1.5);

// i'm linked
llSay(0, "Linked, click to unlink";);
bLink = TRUE;
}
}
}
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
12-28-2009 06:07
Q1) If you re-read the description of the function, you will see that the prim in which you've put the script can be *either* the parent *or* a child in the new object, depending on whether you've said llCreateLink(target, TRUE); // make me the parent in the new object or llCreateLink(target, FALSE); // make me one of the children.

Q2) You put the "useful snippet" in a two-prim object. Then, when you click it, it will unlink, and become two separate objects. Click it again, and it will re-link, with the prim containing the script the root prim, whether or not it was the root previously.

Q3) The comment "// Create a new object and link it as a child prim." describes what the script does.

Q4) "// NOTE: must be a name of an object in this object's inventory." This comment means that value you assign in string ObjectName = "whatever"; has to be the name of an object in the inventory of the prim containing the script.

What's supposed to happen is that the prim containing the script rezzes a new object from its inventory and then links to it, with the prim containing the script as the root prim. The prim can't rez the object unless it can find it in its inventory, for which it needs the object's exact name. So in my little example, there has to be a prim called "whatever" (no quotes) in the object's inventory (if it's called "Whatever" the script won't be able to find it).

Q5) why its say?? - " // Only bother rezzing the object if will be able to link it." -- This comment means what it says -- it's explaining why the code is written as it is.

When you touch the object the script requests permission from the owner to link and unlink, because without the right permissions, it can't do anything. So the author, very sensibly, doesn't rez the object until the run time permissions event, and then only after checking that the object's owner has, in fact, given permission for the object to link and unlink.

So if you click "no" in the dialog about whether the thing can link or unlink, the script doesn't try to perform an operation that's bound to fail and give you an error message.


6) " // This is the parent object. Create a link to the newly-created child." - What is the parent object? what is the newly-created child?

This comment explains what the next line of code,
CODE
 llCreateLink(id, TRUE);
is going to do. Because the PARENT integer is set to TRUE, the object containing the script will be the parent object, and the newly created child will be the prim the script has just rezzed.