I've managed to hack this script together to drop in to a prim so that when you click the prim it gives you the option of what colour light you want it to emit or if you want it to turn off.
The script works fine like this, however, as the Menu submits its answer on a specified channel, then if I use thois script in another object that I want to use as a light nearby, then when I run the script, it alters the object in both lights, as both scripts are listening for the same channel.
What should I be doing to make it so that the menu only affects the one object/script? is the only way to give each script a different channel... this would cause problems should I ever want to sell lights with this script or is there a way so that the script will only listen to itself and not others without using a channel?
In some ways I like the idea of being able to send a message to all lights in range via Chat so that I could turn them all on/off/change colour with a voice command, but I also want the ability to be able to just change the colour of a single light by clicking on it and choosing the colour for that light without it affecting others nearby.
Perhaps I would need 2 scripts per light, 1 that works via chat and listens on a specific channel, and 1 that works as a menu (but doesn't broadcast the command via a channel)
Any guidance would be useful.
Here's the code as it stands
CODE
integer CHANNEL = 567;
float INTENSITY = 1.0;
float RADIUS = 8.0;
float FALLOFF = 1.0;
list COLOR_LIST = ["white", "red", "green", "blue", "yellow", "orange", "purple", "pink", "cyan", "off"];
default {
state_entry()
{
llListen(CHANNEL, "", NULL_KEY, "");
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, INTENSITY, RADIUS, FALLOFF]);
}
touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "Choose a colour to glow?", COLOR_LIST, CHANNEL);
}
listen(integer channel, string name, key id, string message)
{
if (message == "white")
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, INTENSITY, RADIUS, FALLOFF]);
}
else if (message == "pink")
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 0.5, 0.5>, INTENSITY, RADIUS, FALLOFF]);
}
else if (message == "red")
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 0, 0>, INTENSITY, RADIUS, FALLOFF]);
}
else if (message == "orange")
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 0.5, 0>, INTENSITY, RADIUS, FALLOFF]);
}
else if (message == "yellow")
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 1, 0>, INTENSITY, RADIUS, FALLOFF]);
}
else if (message == "green")
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <0, 1, 0>, INTENSITY, RADIUS, FALLOFF]);
}
else if (message == "blue")
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <0, 0, 1>, INTENSITY, RADIUS, FALLOFF]);
}
else if (message == "purple")
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 0, 1>, INTENSITY, RADIUS, FALLOFF]);
}
else if (message == "cyan")
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <0, 1, 1>, INTENSITY, RADIUS, FALLOFF]);
}
else if (message == "off")
{
llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <0, 0, 0>, 0, 0, 0]);
}
}
}