Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Using llSetLinkTexture correctly

Jake Neutron
Registered User
Join date: 3 May 2009
Posts: 6
07-31-2009 10:38
I have a linked set of objects that I want to set the texture of.

At the moment I have a script in each object that I need the texture to change listening for a link_message event, triggered by a llMessageLinked (LINK_SET) call in my main script.

This seems pretty inefficient, and I would like to use the llSetLinkTexture instead.

My question is, how to use this function to set the texture of all the linked objects, apart from two of them, neither of which is the root prim.

At the moment, I'm thinking I will have to get the link numbers of all the prims I need to change the texture of, and work through them using a 'for' loop.

Any suggestions welcome!

Thanks.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
07-31-2009 11:02
you just answered your own question lol.
you can also use the link name if the names of the child prims won't matter, IE;

CODE

default
{
state_entry()
{
string texture = llGetInventoryName(INVENTORY_TEXTURE,0);
integer num = llGetNumberOfPrims();
for(num;num > 0;--num)
{
if(llToLower(llGetLinkName(num)) == "texture me")
{
llSetLinkTexture(num,texture,ALL_SIDES);
}
}
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-31-2009 12:27
You could also use the Description field in each child prim to carry flags that tell the parent what it's allowed to do to the prim. Building on Ruthven's example, here's a script that will let you read multiple flags from each child's Description field and then apply your choice of textures and alpha to selected ones at run time. You could set each child's description to "texture" or "alpha" or "texture alpha" to determine which changes to make when you say the key message.

CODE

integer CHAN = 33;
default
{
state_entry()
{
llListen(CHAN,"",llGetOwner(),"");
}
listen(integer channel, string name, key id, string message)
{
integer num = llGetNumberOfPrims();
for(num;num > 0;--num)
{
if(llListFindList((llGetObjectDetails(llGetLinkKey(num),[OBJECT_DESC]) ),["texture"]) != -1)
{
if (llToLower(message) == "texture1") //Apply "texture1"
{
llSetLinkTexture(num,"texture1",ALL_SIDES);
}
else if (llToLower(message) == "texture2") //Apply "texture2"
{
llSetLinkTexture(num,"texture2",ALL_SIDES);
}
}
else if (llListFindList((llGetObjectDetails(llGetLinkKey(num),[OBJECT_DESC]) ), ["alpha"]) != -1)
{
if (llToLower(message) == "alphaoff") // Make the child visible
{
llSetLinkAlpha(num, 1.0,ALL_SIDES);
}
else if (llToLower(message) == "alphaon") // Make the child invisible
{
llSetLinkAlpha(num,0.0,ALL_SIDES);
}
}
}
}
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-31-2009 15:30
OK... Here's a more complicated script based on Ruthven's. It reads flags from each linked prim's Description field and then, if it sees the right flags, responds to your command on channel 33. In this simple example, the allowed flags are "alpha" and "texture." You can type either one in the Description field of a prim, or neither, or both. If you type both, they must be separated by a comma. A chat command can turn alpha on or off on the identified prims, and can texture identified prims with either of the possible textures (assuming that they're in inventory).

I've tested this script in world and it works well. Question for a more adept scripter..... Is there a cleaner way for me to split out multiple flags from the Description field? My way works OK, but it looks clunky.

CODE

integer CHAN = 33;
default
{
state_entry()
{
llListen(CHAN,"",llGetOwner(),"");
}
listen(integer channel, string name, key id, string message)
{
integer num = llGetNumberOfPrims();
for(num;num > 0;--num)
{
list desc = llParseString2List(llList2String(llGetObjectDetails(llGetLinkKey(num),[OBJECT_DESC]),0),[","],[""]);
if(llListFindList(desc,["texture"]) != -1)
{
if (llToLower(message) == "texture1") //Apply "texture1"
{
llSetLinkTexture(num,"texture1",ALL_SIDES);
}
else if (llToLower(message) == "texture2") //Apply "texture2"
{
llSetLinkTexture(num,"texture2",ALL_SIDES);
}
}
if (llListFindList(desc, ["alpha"]) != -1)
{
if (llToLower(message) == "alphaoff") // Make the child visible
{
llSetLinkAlpha(num, 1.0,ALL_SIDES);
}
else if (llToLower(message) == "alphaon") // Make the child invisible
{
llSetLinkAlpha(num,0.0,ALL_SIDES);
}
}
}
}
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
07-31-2009 16:10
if you have a LOT of child prims to set, and don't want to wait as long as it takes to loops through all those, an alternative would be to use LINK_ALL_OTHERS, from one that won't change, to set all the rest, and then set your other exceptions back to normal via targeting...depending on the object it might be a cleaner solution.

eg
llSetLinkTexture( LINK_ALL_OTHERS, newTexture, ALL_SIDES );
llSetLinkTexture( exceptionPrimInteger, exceptionDefaultTexture, ALL_SIDES );
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-31-2009 16:48
True. As usual, though, once I got thinking about the OP's question I became more intrigued with a side issue. Leaving aside the immediate problem, then,...... If I wanted to use the Description field in a set of linked prims to carry multiple flags -- as I chose to do in my little script -- is there a neater way to parse the flags out of that field than this ....

CODE

list desc = llParseString2List(llList2String(llGetObjectDetail s(llGetLinkKey(num),[OBJECT_DESC]),0),[","],[""]);
if(llListFindList(desc,["texture"]) != -1)
// And so forth


?

It just seems clunky to take a list, convert it to a string, break it into parts and convert it back to a list, and then search the list to see if it contains one of the flags. But maybe that's the best way?
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
07-31-2009 20:35
it'll probably look cleaner if you split it up, but i dunno if it'll be faster/slower than the way you have it. unfortunately, using a list is the only way to get the description from a different prim, which is why i went the name route. which you still could with your script as long as, like i said, the names of the child prims don't matter
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
07-31-2009 20:38
maybe this.....
CODE

list desc = llParseString2List(llList2String(llGetObjectDetails(llGetLinkKey(num),[OBJECT_DESC]),0),[","],[""]);
if(llListFindList(desc,["texture"]) != -1)
// And so forth


could be.....
CODE

string desc = llList2String(llGetObjectDetails(llGetLinkKey(num),[OBJECT_DESC]),0);
if(llSubStringIndex(desc,"texture") != -1)
// And so forth


edited to remove some syntax errors what would have shown up with the snippet
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
07-31-2009 21:06
Not bad... That's a little shorter. I'll test and see if it works. Thanks! :D
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Jake Neutron
Registered User
Join date: 3 May 2009
Posts: 6
08-01-2009 02:18
Thank you for the suggestions people, great stuff!