Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Problem script talking to other scripts

Jonathan Mulberry
Registered User
Join date: 15 Nov 2006
Posts: 106
01-22-2007 03:35
Hi guys,

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]);
}


}
}
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-22-2007 03:48
From: Jonathan Mulberry
Hi guys,

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.


Use a randomly generated channel number rather than a fixed one.

CODE
CHANNEL = 0 - (integer)llFrand(2147483647);


I would also suggest you make the listen only active when required, after the item has been touched, rather than all the time. You will need to add a timer to clear it down after a period of inactivity.

Rather than using an if/else if block take a look at using lists and llListFindList
Jonathan Mulberry
Registered User
Join date: 15 Nov 2006
Posts: 106
01-22-2007 04:20
Thanks Newgate

So if I change the Channel to choose a random one as you suggest, place the llListen in the touch_start, and then some sort of timer to stop it... or could I just tell it to stop listening once an option has been chosen, somewhere after the if/else section.

I'll have a look into the llListFindList thing... not heard of that yet!

I could then use another simple script to permantly listen on a certain channel so that all lights within voice range could be switched on/off/changed colour.... or make a master switch to place on the wall to control them all.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-22-2007 05:12
From: Jonathan Mulberry
Thanks Newgate

So if I change the Channel to choose a random one as you suggest, place the llListen in the touch_start, and then some sort of timer to stop it... or could I just tell it to stop listening once an option has been chosen, somewhere after the if/else section.

I'll have a look into the llListFindList thing... not heard of that yet!

I could then use another simple script to permantly listen on a certain channel so that all lights within voice range could be switched on/off/changed colour.... or make a master switch to place on the wall to control them all.



Basically yes.
You should still add a timer to shut of the listen in case the user wanders off.
Jonathan Mulberry
Registered User
Join date: 15 Nov 2006
Posts: 106
01-22-2007 05:44
One other thought.....

I think I'm correct in saying that the default state_entry bit is only run once and the state of the object/script is saved when you take it in to you inventory so if you re-rez it, it the state will be as it was when you took it back to your inventory.

Now, if I was to sell copies of the object then I presume that when they rez it, it would be in the same state as the original it was bought from (in this case having the same colour light).... would this also apply to the random channel, or would that be reset as its not in the default state_entry, but before the default state_entry commands. In otherwords would all the copies bought all end up running on the same channel because the state was saved with the object.

I hope that makes sense.... its onfusing me reading it back... lol

I think what I'm trying to say is should the random channel integer be run when called from state_entry and from an on_rez command so that each item when bought is guarenteed to use a random channel or will the random channel integer always execute anyway?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-22-2007 05:59
From: Jonathan Mulberry
One other thought.....

I think I'm correct in saying that the default state_entry bit is only run once and the state of the object/script is saved when you take it in to you inventory so if you re-rez it, it the state will be as it was when you took it back to your inventory.

Now, if I was to sell copies of the object then I presume that when they rez it, it would be in the same state as the original it was bought from (in this case having the same colour light).... would this also apply to the random channel, or would that be reset as its not in the default state_entry, but before the default state_entry commands. In otherwords would all the copies bought all end up running on the same channel because the state was saved with the object.

I hope that makes sense.... its onfusing me reading it back... lol


you can use an on_rez event to handle that situation BUT you should be assigning the random channel in the touch event, i.e.a new random channel on every touch.

If you're interested, thsi thread covers a very similar subject.
Jonathan Mulberry
Registered User
Join date: 15 Nov 2006
Posts: 106
01-22-2007 06:04
heh... you just beat me to it Newgate, I'd just altered my previous post to mention on_rez. But of course.... it makes much more sense to execute the random channel in the touch event.

Thanks for your help. Just need to finish work so I can go play with the script now.