Difference between revisions of "LlCreateLink"

From Second Life Wiki
Jump to navigation Jump to search
m (moved func_footer to func_footnote: attempt to correct order in function category)
 
(20 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{LSL_Function/permission|PERMISSION_CHANGE_LINKS|grant=the owner}}{{LSL_Function
{{LSL_Function
|func_id=141|func_sleep=1.0|func_energy=10.0
|inject-2={{LSL_Function/permission|PERMISSION_CHANGE_LINKS|grant=the owner}}{{LSL_Function/prim|target|sim=*}}
|func_id=141|func_sleep=0.1|func_energy=10.0
|func=llCreateLink|sort=CreateLink
|func=llCreateLink|sort=CreateLink
|p1_type=key|p1_name=target|p1_desc=A prim in the same region.
|p1_type=key|p1_name=target
|p2_type=integer|p2_name=parent|p2_desc=If [[FALSE]], then '''target''' becomes the root.
|p2_type=integer|p2_name=parent
|func_footnote='''target''' must be modifiable and have the same owner.<br/>
|p2_desc=If [[FALSE]], then {{LSLP|target}} becomes the root. If [[TRUE]], then the script's object becomes the root.
|p2_hover=If FALSE, then 'target' becomes the root. If TRUE, then the script's object becomes the root.
|func_footnote={{LSLP|target}} must be modifiable and have the same owner.<br/>
This object must also be modifiable.
This object must also be modifiable.
|func_desc=Attempt to link the script's object with '''target'''.
|func_desc=Attempt to link the script's object with {{LSLP|target}}.
|spec
|spec=The prims for the child object ({{LSLP|target}} if {{LSLP|parent}} is [[TRUE]], script's object if {{LSLP|parent}} is [[FALSE]]) are inserted into the parent object's link set starting at link number 2. For example, if the link order for the parent object is A1, A2, A3 and the link order of the child object is B1, B2, B3, then the link order of the resulting object will be A1, B1, B2, B3, A2, A3.
|caveats=*Shouts an error on [[DEBUG_CHANNEL]] if '''target''' isn't in the region or an object.
|caveats=*If {{LSLP|target}} is not in the region, not a prim, or is attached to an avatar, an error is shouted on [[DEBUG_CHANNEL]].
*If either the object or the '''target''' are not modifiable or of different owners, then an error is shouted on [[DEBUG_CHANNEL]].
*If either the object or the {{LSLP|target}} are not modifiable or of different owners, then an error is shouted on [[DEBUG_CHANNEL]].
*If the the parent object and {{LSLP|target}} are too far apart they will fail to link.
**The maximum distance is further explained here: [[Linkability Rules]]
*This function silently fails if called from a script inside an attachment.
|constants
|constants
|examples
|examples=<source lang="lsl2">// Rez an object and link it as a child prim.
|helpers
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);
    }
}</source>
 
|helpers=
<source lang="lsl2">
// 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;
        }
    }
}             
</source>
|also_functions={{LSL DefineRow||[[llBreakLink]]|Break a link}}
|also_functions={{LSL DefineRow||[[llBreakLink]]|Break a link}}
{{LSL DefineRow||[[llBreakAllLinks]]|Break all links}}
{{LSL DefineRow||[[llBreakAllLinks]]|Break all links}}
|also_tests
|also_tests
|also_events
|also_events={{LSL DefineRow||[[changed]]|[[CHANGED_LINK]]}}
|also_articles
|also_articles=
{{LSL DefineRow||[[Linkability Rules]]|}}
|notes
|notes
|cat1=Link
|cat1=Link
|cat2
|cat2=Link/Management
|cat3
|cat3
|cat4
|cat4
}}
}}

Latest revision as of 13:01, 21 November 2023

Summary

Function: llCreateLink( key target, integer parent );
0.1 Forced Delay
10.0 Energy

Attempt to link the script's object with target.

• key target prim UUID that is in the same region
• integer parent If FALSE, then target becomes the root. If TRUE, then the script's object becomes the root.

To run this function the script must request the PERMISSION_CHANGE_LINKS permission with llRequestPermissions and it must be granted by the owner. target must be modifiable and have the same owner.
This object must also be modifiable.

Specification

The prims for the child object (target if parent is TRUE, script's object if parent is FALSE) are inserted into the parent object's link set starting at link number 2. For example, if the link order for the parent object is A1, A2, A3 and the link order of the child object is B1, B2, B3, then the link order of the resulting object will be A1, B1, B2, B3, A2, A3.

Caveats

  • This function causes the script to sleep for 0.1 seconds.
Permissions
  • If target is not in the region, not a prim, or is attached to an avatar, an error is shouted on DEBUG_CHANNEL.
  • If either the object or the target are not modifiable or of different owners, then an error is shouted on DEBUG_CHANNEL.
  • If the the parent object and target are too far apart they will fail to link.
  • This function silently fails if called from a script inside an attachment.

Examples

// Rez an 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;
        }
    }
}

See Also

Events

•  run_time_permissions Permission receiving event
•  changed CHANGED_LINK

Functions

•  llGetPermissions Get the permissions granted
•  llGetPermissionsKey Get the agent who granted permissions
•  llRequestPermissions Request permissions
•  llBreakLink Break a link
•  llBreakAllLinks Break all links

Articles

•  Script permissions
•  Linkability Rules

Deep Notes

Signature

function void llCreateLink( key target, integer parent );