Make 2 Prims talk to each other in SecondLife

secondlife-communicate

Someone asked the follow question on StackOverflow.com:

I’m writing an LSL script attached to an object, and would like to change the transparency of another object which I have the UUID of (stored in a key variable).

I’ve read the documentation but can’t even work out how to change the name/description of another object, let alone the transparency. I can only find methods for modifying the local object.

Does LSL not support modification of the properties of other objects, even when they’re in the same region and have the same owner?

I hadn’t really thought about this much before. When I build my scripts are all communicating with each other because I link all of the objects together.  I hopped online and started experimenting.  Since objects can’t “hear” chat by default, I had to do it a little differently.  My answer to him is below.  Hopefully this can come in handy for anyone looking to have to unlinked prims communicate.  Note: With this method they’ll have to be in the same Region.

 

If it’s in the same region then you could just add llListen() in one prim and use llRegionSay() in the other on a private channel.

Like this:

Prim 1 Script (Prim sending the command)


default
{
state_entry()
{
}

touch_start(integer total_number)
{
llRegionSay(-123456,"1.0"); // Channel -123456 can be anything. "1.0" will be the transparency setting passed to the 2nd prim
}
}

Prim 2 Script (Prim receiving the command)


default
{
state_entry()
{
llListen(-123456, "", "", ""); // Make the prim listen
}

listen( integer channel, string name, key id, string message )
{
if (channel==-123456) { // Match the same private channel
llSetAlpha((integer)message, ALL_SIDES); // Convert "message" into an integer and pass to the llSetAlpha() function as the transparency - 0 = invisible 1 = visible
}
}
}

Does anyone have any other ideas about how to do this?  I’m curious to hear what you think.