Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

message passing synchronizer

Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
05-17-2007 16:48
People often ask how to synchronize two or more objects. Here is a simple approach using shouts.

Put this script into two or more objects. You can put the channel number in the script itself, or you can put it in the object description (and enable the llGet() ).

When you touch one of the objects, it sends a message to the channel, and then performs
the action. If repeat is more than one, it will send the message that many times, which is useful if the message isn't arriving all the time.

When an object hears the message, it preforms action.

Just as an example, this script causes all the objects to change color at more or less the same time.

CODE


integer ch = -5191928; // put the channel number here, or in the object description
integer repeat = 2;

// send a message to all the others on the channel
sending()
{
vector color = <llFrand(1), llFrand(1), llFrand(1)>;
integer r = repeat;

// if you want to be sure, send the message more than once.
while( r > 0 ) {
llShout(ch, (string) color );
--r;
}

acting( color );
}

// Do whatever the action is.
acting( vector c )
{
llSetColor( c, ALL_SIDES );
}


default
{
state_entry()
{
//llSay(0, "Hello, Avatar!");
//ch = (integer) llGetObjectDesc();
llListen( ch, "", "", "" );
}

listen(integer c, string n, key k, string m)
{
acting( (vector) m );
}

timer()
{
//action();
}

touch_start(integer total_number)
{
llSay(0, "Sending...");
sending();
}
}

Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
05-18-2007 06:55
/54/60/184732/1.html
_____________________
i've got nothing. ;)