Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

MessageLinked and linked_message example

ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
09-21-2006 09:20
I found the MessageLinked and linked_message description and example in the LSL Wiki to be somewhat cryptic. Probably due to my inexperience as a script writer. But I did eventually sort it out and am contributing this example of how the sender script in a parent prim can control three child prims. In this example touching the linked set sends a message from the parent prim to the three child prims, turning them invisible one after the other with each touch. The invisibiliy is accomplished using the llSetAlpha call, it could be replaced with many other calls in order to change textures or primitive paramaters, etc. I tested this example in SL this morning and a free sample of the example prims and scripts is available in my box of "Free useful stuff" at my store in Shona. See the coordinates in my signature below.

Sender script to be placed in parent prim:
CODE
//This sender script acts as an touch activated switch  to show/hide other linked prims
//When touched it sends MessageLinked commands...
// to link_message receiver scripts in the linked prims to make them visible/invisible (on/off).
//To see this script in action create one cube and three spheres.
//Name the cube Parent/switch and the three spheres top, middle, bottom.
//stack the spheres on top of the cube, bottom, middle, top.
//Link the three spheres to the cube so the cube is the parent prim.
//Place this MessageLinked script in the cube, the parent prim.
//Place the other three Link_message scripts, one in each sphere with the matching name.



default //sends message to turn bottom on and others off.
{
touch_start(integer total_number)
{
//llWhisper(0, "bottom on");
llMessageLinked(LINK_SET, 0, "bottomOn", NULL_KEY);
llMessageLinked(LINK_SET, 0, "middleOff", NULL_KEY);
llMessageLinked(LINK_SET, 0, "topOff", NULL_KEY);
state middleOn;
}
}

state middleOn //sends message to turn middle on and others off.
{
touch_start(integer total_number)
{
//llWhisper(0, "middle on");
llMessageLinked(LINK_SET, 0, "bottomOff", NULL_KEY);
llMessageLinked(LINK_SET, 0, "middleOn", NULL_KEY);
llMessageLinked(LINK_SET, 0, "topOff", NULL_KEY);
state topOn;
}
}

state topOn //sends message to turn top on and others off.
{
touch_start(integer total_number)
{
//llWhisper(0, "top on");
llMessageLinked(LINK_SET, 0, "bottomOff", NULL_KEY);
llMessageLinked(LINK_SET, 0, "middleOff", NULL_KEY);
llMessageLinked(LINK_SET, 0, "topOn", NULL_KEY);
state default;
}
}



Receiver script to be placed in bottom child prim:
CODE
// link_message reciever to turn alpha/transparancy on and off
// place this script in the bottom sphere
// it listens for the messages "bottomOn" and "bottomOff".
// to make it do other things replace the "SetAlpha" call with a different one
// or add calls to it.

Alpha_On()
{
llSetAlpha(1.0,ALL_SIDES); //1.0 shows all of the texture, no transparency
}

Alpha_Off()
{
llSetAlpha(0.0,ALL_SIDES); //0.0 shows none of the texture, it is transparent.
}

default
{
link_message(integer sender, integer num, string message, key id)
{
if(message == "bottomOn") Alpha_On();
if(message == "bottomOff") Alpha_Off();
}
}


Receiver script to be placed in middle child prim:
CODE
//link_message reciever to turn alpha/transparancy on and off
// place this script in the middle sphere
// it listens for the messages "middleOn" and "middleOff".
// to make it do other things replace the "SetAlpha" call with a different one
// or add calls to it.

Alpha_On()
{
llSetAlpha(1.0,ALL_SIDES); //1.0 shows all of the texture, no transparency
}

Alpha_Off()
{
llSetAlpha(0.0,ALL_SIDES); //0.0 shows none of the texture, it is transparent.
}

default
{
link_message(integer sender, integer num, string message, key id)
{
if(message == "middleOn") Alpha_On();
if(message == "middleOff") Alpha_Off();
}
}


Receiver script to be placed in top child prim:
CODE
// link_message reciever to turn alpha/transparancy on and off
// place this script in the bottom sphere
// it listens for the messages "topOn" and "topOff".
// to make it do other things replace the "SetAlpha" call with a different one
// or add calls to it.


Alpha_On()
{
llSetAlpha(1.0,ALL_SIDES); //1.0 shows all of the texture, no transparency
}

Alpha_Off()
{
llSetAlpha(0.0,ALL_SIDES); //0.0 shows none of the texture, it is transparent.
}

default
{
link_message(integer sender, integer num, string message, key id)
{
if(message == "topOn") Alpha_On();
if(message == "topOff") Alpha_Off();
}
}
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
09-21-2006 22:36
/54/aa/138990/1.html
_____________________
i've got nothing. ;)