Linksets in SecondLife (1)

Suppose you have a nice car that you got for free at a freebie store. Your car has all the permissions, it is copyable, modifiable and you can transfer it to another avatar.

You decide that you can improve it, adding other objects that you have found for free. Perhaps you like to put on the hood a skull with horns and a spare wheel at the rear and to give it a more "MadMax" look like metal window grilles.

By doing so, you discover that your brand new car has stopped working. Maybe instead of turning the wheels, the seats turn, the lights are no longer on, and the particle emitters are wrong.

  Many scripts assume that a primitive within the primitive set will always have the same binding number, and when primitives are added or removed the script crashes.

I'm going to create a few scripts to see what exactly is going on.

Script: LinkSpy.lsl



PutTextInfo()
{
    string sMessage = "Link: " + (string) llGetLinkNumber() + "\n";

    list lResult = llGetLinkPrimitiveParams(LINK_THIS, [ PRIM_PHYSICS_SHAPE_TYPE ]);
    integer iTipo = llList2Integer(lResult, 0);
    string sTipo = "";
    if (iTipo == PRIM_PHYSICS_SHAPE_PRIM)
    {
        sTipo = "PRIM";
    }
    else if (iTipo == PRIM_PHYSICS_SHAPE_CONVEX)
    {
        sTipo = "CONVEX";
    }
    else if (iTipo == PRIM_PHYSICS_SHAPE_NONE)
    {
        sTipo = "NONE";
    }
    
    sMessage += sTipo;
    
    llSetText(sMessage, <1.0, 1.0, 1.0>, 1.0);
}


default
{
    state_entry()
    {
        PutTextInfo();
    }

    touch_start(integer total_number)
    {
        PutTextInfo();
    }
    
    changed(integer change)
    {
        if ((change & CHANGED_LINK) == CHANGED_LINK) 
        {
            PutTextInfo();
        }
    }
    
}





To experiment we will create several primitives and in each of them we will put the script "LinkSpy.lsl". In each and every one of those primitives we will see the floating text "Link 0 PRIM". When linking two primitives their respective floating texts will change, the last selected primitive will have "Link 1: PRIM" and the following "Link: 2 PRIM". I add several more primitives until I have 8 primitives numbered from 1 to 8. Primitive 1 is the root primitive and the rest are daughter primitives.

In the upper half of the image below we see that the primitives are perfectly ordered from number 1 to number 8.
The second line is the type of physics that I have assigned to the primitive. That is to say; "Prim", "Convex" and "None". As the script is not able to detect when we change the physics of a primitive, we have to click on that primitive to refresh it.




At the bottom of the image, we see that I have added two primitives to the linkset. But something has happened that is not expected when you are inexperienced. The two primitives do not have the link numbers 9 and 10. Instead they have the numbers 2 and 3. The primitive that previously had the number 2 now has the number 4.

This feature is well documented (http://wiki.secondlife.com/wiki/LlCreateLink). Even so many scripts usually fail when this happens.

In the next post, I will discuss developing a script to be able to safely add primitives to a linkset. Meanwhile I also add a small script that I will need to simulate the errors that some scripts produce when I add primitives.


Script: AnnoyingScript.lsl

default
{
    state_entry()
    {
        
    }

    changed(integer change)
    {
        if ((change & CHANGED_LINK) == CHANGED_LINK) 
        {
            llOwnerSay("I am the anoyning script generating errors when you change the linkset");
        }
    }

}









Comments

Popular posts from this blog

Reading headers in a PHP script

snippet - Limit floats numbers and vectors to 2 digits.

All my things temporarily removed from Marketplace.