Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Making a color change script more efficiant

RaptonX Zorger
Registered User
Join date: 26 Jan 2006
Posts: 79
04-09-2006 14:47
Ok, I was told that using messages for triggeing color sawps in each prim in an ave puts more stress o na sim, and that I should use message link, which reqires me to do it all by knowing the linknum of each prim. But if I modify a certian attatchment, wouldn't that change it, requiring me to redo the script all over again.

Is there a way I can call prims in an object by name maybe, and any with one particualr name will be affected in one way, while others with another name would be affected in another way?

Otherwise I'll just go ahead with putting a listen script in each prim.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
04-09-2006 15:10
From: someone

LINK_ROOT 1 root prim in linked set (but not in a single prim, which is 0)
LINK_SET -1 all prims in object
LINK_ALL_OTHERS -2 all other prims in object besides prim function is in
LINK_ALL_CHILDREN -3 all child prims in object
LINK_THIS -4 prim script is in


llMessageLinked(integer linknum, integer num, string str, key id)

all those things after the function can act as filters

so you could have the other scripts respond to a certain number (as defined in integer num)
or a string (string str) or a UUID

ie

CODE

default
{
state_entry()
{
llMessageLinked(-1,2,"",NULL_KEY);
}
}


on the other end

CODE


link_message(integer sender_num, integer num, string str, key id)
{
if (num == 2) do stuff
}

RaptonX Zorger
Registered User
Join date: 26 Jan 2006
Posts: 79
04-09-2006 16:54
From: Osgeld Barmy
llMessageLinked(integer linknum, integer num, string str, key id)

all those things after the function can act as filters

so you could have the other scripts respond to a certain number (as defined in integer num)
or a string (string str) or a UUID

ie

CODE

default
{
state_entry()
{
llMessageLinked(-1,2,"",NULL_KEY);
}
}


on the other end

CODE


link_message(integer sender_num, integer num, string str, key id)
{
if (num == 2) do stuff
}





Awesome..thanks :)
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-10-2006 08:12
One thing I've done for this kind of thing is to use the name of the prim to determine its identity in the link set.

For what you're doing, though, llSetLinkColor may be even more efficient.
Persephone Milk
Very Persenickety!
Join date: 7 Oct 2004
Posts: 870
04-10-2006 10:56
I use the method that Argent is suggesting. Since the name of each prim in a linked set does not really matter (except for the root prim, which becomes the name of the object), the name property can be used to store all kinds of information. As I enumerate through the prims in my object I can check the value of the name property to determine what type of prim it is, and act accordingly.

For example, let's say that I create an object with many prim, and I divide these prim into three groups: non-colorable, colorable group 1, and colorable group 2. I would like to be able to change the color of the two groups of colorable prims programmatically, and independently. To do this, I might add "cg1" and "cg2" to the name property of these prims. Then, when I want to change the color of prims in colorable group 1, I only act on prims that have "cg1" in their name property.

This way the link order does not matter at all. You do not need to be worried about linking and unlinking in the correct sequence. Just name your prims and the conditional logic in your loop will apply the correct colors to each prim.

The only negative I have found to this method is that for the root prim to be colorable, you would have to include the tag in the object name. While this might not seem too bad, if you are selling your item and include mod rights, your customer may change the name of your item and not know to include the tag in the name. In cases like this, sometimes the easiest fix is to just manually except the root in your code. It's not as elegant, but it works.

Also note that you can also change the transparency value for linked prim ... in addition to color.
_____________________
~ Persephone Milk ~

Please visit my stores on Persenickety Isle
Musical Alchemy - Pianos, harps and other musical intruments.
Persenickety! - Ladies Eyewear, Jewelry and Clothing Fashions
Zalandria Zaius
Registered User
Join date: 17 Jan 2004
Posts: 277
little script that shows the name thing in action
04-10-2006 11:05
CODE

//Name the items ,in the link set, that you want to change color "Color Me" without the quotes. Reset the script and your good to go.

list colorthese;
default
{
state_entry()
{

integer i;
for(i = 0;i <= llGetNumberOfPrims();i++)
{
if(llGetLinkName(i) == "Color Me")
{

colorthese += i;
}
}
}

touch_start(integer total_number)
{

vector randomcolor = <llFrand(1),llFrand(1),llFrand(1)>;
integer i;
for(i = 0;i <= llGetListLength(colorthese);i++)
{

llSetLinkColor(llList2Integer(colorthese,i),randomcolor,ALL_SIDES);
}
}
}