Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Texture change script for linked prims

Dorra Debs
Poptart
Join date: 20 Jul 2005
Posts: 177
03-25-2007 12:32
I need a script that will change the texture of a linked set of prims with 1 click. I see from doing a search that there are texture change scripts, but each prim must be clicked to make the change. Any ideas?
_____________________
Vlad Bjornson
Virtual Gardener
Join date: 11 Nov 2005
Posts: 650
Random Texture Changes on a Linked Group Script
03-25-2007 13:22
Here is something similar that I wrote for a tree that changes bark and leaf textures randomly.

It's a pair of scripts that will change the Parent object to one random texture and each linked object to another random texture. It might be easily modified for other purposes.

This script goes into the Parent object:

CODE
// Random Texture Changing for Linked Object - Parent
// by Vlad Bjornson - free to use and modify

// Put this script in the Parent object to capture the touches and send the signal to change textures. There is also a Child scrip that goes in each of the other linked group objects.


// UUIDs of textures

list ParentTextures = ["e74aab9f-493e-5f89-e00f-967726f94cc8","fa9c5e95-d024-7a1a-8920-0c80e31ff300","549a9343-c4a7-3184-dbb9-630c896cba6d","f8ebf521-8117-d3d2-3d67-9c8b57db5eab","0671bf54-34b5-4495-6e07-7b71dc2cfa5f","860d82af-d87e-1265-b58a-cbc01c193ad5"];


integer NumTextures;
integer RndChild = 1;
integer RndParent = 1;


default
{
state_entry()
{
NumTextures = llGetListLength(ParentTextures);
}


touch_start(integer total_number)
{


RndParent = (integer) llFrand( (NumTextures) );
RndChild = (integer) llFrand( (NumTextures) );
llMessageLinked(LINK_ALL_OTHERS, RndChild, (string) RndParent, "");
llSetTexture(llList2String(ParentTextures,RndParent), ALL_SIDES);

}
}



and this script goes into each of the other linked objects:

CODE
// Random Texture Changing for Linked Object - Child
// by Vlad Bjornson - free to use and modify

// Put this script in each of the child objects in your linked group. This script reacts to the command to change textures - and a number that says which random texture to use. There is another script that goes in the Parent object.

// Note: The script assumes that there are the same number of textures for the parent and child prims.


// UUIDs of textures


list ChildTextures = [
"44374526-d4a1-64cf-df90-aa0460d37f70",
"c9b5b1d3-575f-0873-91fd-93b0ffde7290",
"fceaec76-4d36-2eee-6693-242c39b27cd8",
"0821fd23-5144-940a-24b2-cf48d6278de7",
"940150e2-05d6-0293-6ddc-1fe20859004c",
"324fc5ca-eed4-f215-f056-8cfc17d4e017"
];

// oakleaf final, fallleaves, Yellow, Green1, drk green, grn light


default
{
link_message(integer sender, integer TextureNumber, string texture, key k)
{

llSetTexture( llList2String(ChildTextures, TextureNumber ) , 1);

}
}
Dorra Debs
Poptart
Join date: 20 Jul 2005
Posts: 177
03-25-2007 15:54
I know next to nothing about scripting and don't have a clue how to modify the script posted. I did try the scripts and cant seem to get the children to behave properly. *mumbles about rotten kids*
_____________________
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
03-25-2007 20:27
With the new llSetLinkTexture() function, there is now a better way to do this, which only requires a single script. No longer do you need a script in every prim. I'll try to write a brief example here.
CODE

integer total;
integer index;

default {
state_entry() {
total = llGetInventoryNumber(INVENTORY_TEXTURE);
}
changed (integer change) {
if (change & CHANGED_INVENTORY) llResetScript();
}
touch_start(integer num_detected) {
if (index == total) index = 0;
string texture = llGetInventoryKey( llGetInventoryName(INVENTORY_TEXTURE, index++) );
llSetLinkTexture(LINK_SET, texture, ALL_SIDES);
}
}
Vlad Bjornson
Virtual Gardener
Join date: 11 Nov 2005
Posts: 650
03-25-2007 21:06
Hey, wow - that is great! thanks for the info DoteDote. That is so much simpler :)