I had my first hands on prim communication, but obviously I seem to do something wrong.
Pretty sure someone can point me to the right way.
The setup: I want to make a box made of 5 siding prims, having the sides react to commands from the root prim.
The commands are light on/off and color change to change the color of the box' inner side, so issuing the color change is meant to change the color of one face of the sub prim.
Therefore I made 2 scripts, one (lightColorSwitch) to be placed in the root prim providing the menu, and the second (subPrimListen) to be placed in each siding prim listening to the commands and change the color or light respectively.
The color change is communicated by llMessageLinked(), the color vector transmitted as string to the sub prim.
I made the prims, linked them together to a box, put the scripts in and: Ok - it works, so far, so good.
But: When put two boxes side by side (not linked to each other), _both_ boxes react to the commands I issue from either box.
So the communications seems not to be limited to the own link set but also affects an object standing next to it, reacting to the same commands.
Can anyone please help me to understand what's going on and how to transmit the information keeping it in the box so that two boxes side by side can be controlled to have different colors?
Many thanks in advance
Cathy
Here's the code:
CODE
// --- lightColorSwitch
// --- Coloring / Light menu
integer menuChannel = 94;
integer linkChannel = 96;
integer index = 0;
list MENU_MAIN = ["Light on", "Light off", "Color..."];
list MENU_COLOR = ["White", "Red", "Orange", "Yellow", "Green", "Mint", "Blue", "Purple", "Pink"];
list COLORS = [<1.0,1.0,1.0>,<1.0,0.0,0.0>,<1.0,0.5,0.0>,<1.0,1.0,0.0>,<0.0,1.0,0.0>,<0.0,1.0,0.5>,<0.0,0.0,1.0>,<0.5,0.0,1.0>,<1.0,0.0,0.5>];
string vecString = "<0.0,0.0,0.0>";
vector colorVector;
default
{
state_entry()
{
llListen(menuChannel, "", NULL_KEY, ""); // listen for dialog answers (from multiple users)
}
touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "Select options", MENU_MAIN, menuChannel); // present dialog on click
}
listen(integer channel, string name, key id, string message)
{
if (channel == menuChannel)
{
if (llListFindList(MENU_MAIN + MENU_COLOR, [message]) != -1) // verify dialog choice
{
if (message == "Light on")
{
llMessageLinked(LINK_SET,linkChannel,"light_on",NULL_KEY);
}
else if (message == "Light off")
{
llMessageLinked(LINK_SET,linkChannel,"light_off",NULL_KEY);
}
else if (message == "Color...")
{
llDialog(id, "Select lighting color", MENU_COLOR, menuChannel);
}
else
{
index = llListFindList(MENU_COLOR, [message]);
colorVector = llList2Vector(COLORS, index);
vecString = (string) colorVector;
llMessageLinked(LINK_SET,linkChannel,vecString,NULL_KEY);
}
}
}
}
}
CODE
// --- subPrimListen
// --- listen for lighting/color messages
integer myFace = 1;
integer light_on = FALSE;
vector color;
setLight()
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, light_on, color, 1.0, 10.0, 0.75, PRIM_FULLBRIGHT, myFace, light_on]);
llSetColor(color, myFace);
}
default
{
state_entry()
{
light_on = FALSE;
color = llList2Vector(llGetPrimitiveParams([PRIM_POINT_LIGHT]),1);
setLight();
}
link_message(integer sender_num, integer num, string str, key id)
{
if (sender_num == 1) // root-Prim
{
if (str == "light_on")
{
light_on = TRUE;
setLight();
return;
}
else if (str == "light_off")
{
light_on = FALSE;
setLight();
return;
}
else
{
color = (vector) str;
setLight();
}
}
}
}
