Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help Needed on Listen Messages

smoky Sweetwater
Very Intrested Lurker ...
Join date: 7 Nov 2008
Posts: 19
11-22-2009 16:57
Hi Everyone

I throw myself my your pity again lol ........ I have spend all day trying to solve this one using the wiki and freebie scripts, with no luck (or maybe just my brain lol) so any help would be appreciated !!

I am trying to create a controller dialog button that operates all of the blinds in my skybox i.e. opens and closes them. They are linked to several different parts of the build as one blind is on a door, etc so I thought that a dialog listen message would work best.

i have the controller button that speaks on channel 123456789 and that works, it does talk the the other prims.

But when i hit the open button, it both opens and closes in one button hit !!!! it doesnt stay in one place either open or close!!!!!!!

Can anyone please look at the following script and point out where I am going wrong please? i love to learn by experiment but I have no idea on this one where I am going wrong....... so if this is so simple to you all sorry but I am having total brain lock !!


vector offset = <0,0,1>; //Prim moves/changes size along this local coordinate
float hi_end_fixed = FALSE; //Which end of the prim should remain in place when size changes?
//The one with the higher (local) coordinate?
float min = 0.2; //The minimum size of the prim relative to its maximum size
integer ns = 10; //Number of distinct steps for move/size change {


//Used to activate/deactive a listen
integer listen_handle = 0;
integer channel = 123456789;

default {
state_entry()
{

llListen(channel, "",NULL_KEY, "";);

}

listen(integer channel, string name, key id, string message) {


if (message=="close";) {
offset *= ((1.0 - min) / ns) * (offset * llGetScale());
hi_end_fixed -= 0.3;
}



else if (message=="open";)
//(integer, ns = 10)
{

integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
while ((++i) < ns);
offset = - offset;
}
}
}


Many Thanks for any help you can give a learning scripter !!
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-22-2009 17:04
The problem is probably in the script that calls this one. If you are using a touch event, don't. Use touch_start or touch_end instead. Touch events fire repeatedly as long as you have your finger on the mouse button, so you'll almost always get bounces. Touch_start or touch_end will each fire once.

Of course, if that's not the problem, we'll try something else.....
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
smoky Sweetwater
Very Intrested Lurker ...
Join date: 7 Nov 2008
Posts: 19
11-22-2009 17:29
Hi

Thanks for your quick reply..... :))

Sorry to be a pain but I am using touch_Start in the controller button.

I can send you the prim I am playing with.... if that would help?

Thanks
Smoky
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-22-2009 18:13
Probably not, but if the script isn't too long, try posting it here.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Laurie Stilman
Registered User
Join date: 11 Apr 2006
Posts: 45
11-22-2009 21:05
From: smoky Sweetwater

listen(integer channel, string name, key id, string message) {
if (message=="close") {
offset *= ((1.0 - min) / ns) * (offset * llGetScale());
hi_end_fixed -= 0.3;
}
else if (message=="open")
//(integer, ns = 10)
{
integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
while ((++i) < ns);
offset = - offset;
}
}


When the script gets a 'close' message, you set offset and hi_end_fixed, buy don't apply them (you don't modify the prim). Then, when the script gets an 'open' message, it applies the values you set on 'close', closing the blinds, and loops to open them...

In other words, your blinds wont change on 'close', and with close then open on 'open'.
smoky Sweetwater
Very Intrested Lurker ...
Join date: 7 Nov 2008
Posts: 19
11-24-2009 11:55
From: Laurie Stilman
When the script gets a 'close' message, you set offset and hi_end_fixed, buy don't apply them (you don't modify the prim). Then, when the script gets an 'open' message, it applies the values you set on 'close', closing the blinds, and loops to open them...

In other words, your blinds wont change on 'close', and with close then open on 'open'.



Hiya

Thanks for the response, that is exactly what happens!!!!

ok, I need to stop the script from looping then, i think?

i will have a play and see what i can do.

Many Thanks


EDIT:
No i dont, do i? what i need to do is put the first bit into a llSetPrimitiveParams ????
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-24-2009 12:13
Nope. When you wrote the code to open the blinds, you just forgot to put similar code in the the block that says what to do when the message is "close."
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
smoky Sweetwater
Very Intrested Lurker ...
Join date: 7 Nov 2008
Posts: 19
Would this work????
11-24-2009 15:53
Thanks for your help so far

Sorry if I sound dense, I will get my head around this

Just been playing around, do you think this will work better? I have added a listen remove after each statement, I think that will stop it from looping? maybe?

And added, the prim para bit at the top so it actually does something now?

vector offset = <0,0,1>;
float hi_end_fixed = FALSE;
float min = 0.5;
integer ns = 10;
integer listen_handle = 123456789;
integer channel = 123456789;

default {
state_entry() {

llListen(channel, "",NULL_KEY, "";)

listen(integer channel, string name, key id, string message);
}
{
if (message=="close";)
//This was the old settings
// offset *= ((1.0 - min) / ns) * (offset * llGetScale());
// hi_end_fixed -= 0.3;

do llSetPrimitiveParams([PRIM_SIZE, offset *= ((1.0 - min) / ns) * (offset * llGetScale()),
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed -= 0.3) * llGetLocalRot())]);

llListenRemove(listen_handle);}

if (message=="open";)
//(integer, ns = 10)
{
integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
while ((++i) < ns);
offset = - offset;
}
llListenRemove(listen_handle);
}}
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-24-2009 16:50
Nope. The llListenRemove statements don't do a thing. Take a look at this. It works. See if you can figure out why.

CODE

vector offset = <0,0,1>;
float hi_end_fixed = FALSE;
float min = 0.2;
integer ns = 10;
integer chan = 100;

default {
state_entry() {
offset *= ((1.0 - min) / ns) * (offset * llGetScale());
hi_end_fixed -= -0.5;
llListen(chan, "","","");
}

listen(integer channel, string name, key id, string message) {
integer ON = 1;
if (llToLower(message) == "close"){
ON = -1;
}
integer i;
do llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset*ON,
PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset*ON) * llGetLocalRot())]);
while ((++i) < ns);
}
}


I used a positive channel (100) so I could send a message in chat to test it. Saying anything but "close" will open the blind. "Close" closes it.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
smoky Sweetwater
Very Intrested Lurker ...
Join date: 7 Nov 2008
Posts: 19
Thank you so much
11-27-2009 14:20
Hi Rolig

Thanks so much for helping me!

Does it work because:

The listen is after the 'tell the prim what to do bit' at the start? as in we (you lol) set the default position of the prim at the outset?

then by saying listen to the close only, do this to the prim instead? and this stops the looping that i had before?

I hope I have got that right?, i really want to learn and understand the why!

You have also added in a llToLower (I have never come across that one as yet, more reaserch on the wiki needed) and turned integer to ON and set that to 1, so it moves to the correct offset, just -1 rather than using ++i bit? which was very compliated (to my head anyway)

Thanks so much for helping me with this.

Also, can I ask why the listen messages dont work? is this in general or just in this script they were no use?

Thanks so much again for all of your help
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-27-2009 17:03
From: smoky Sweetwater
Hi Rolig

Thanks so much for helping me!

Does it work because:

The listen is after the 'tell the prim what to do bit' at the start? as in we (you lol) set the default position of the prim at the outset?

The way LSL works, it doesn't make any difference what order you write the various events in. An event is executed only when it is triggered. The state-entry event is triggered whenever the script is reset, so that's a good place to initialize any variables you are going to use later. That's why offset and hi_end_fixed are given starting values there.
From: someone
then by saying listen to the close only, do this to the prim instead? and this stops the looping that i had before?

Actually, the reason for only listening for the message "close" is that a curtain only has two positions. If a message comes in that isn't "close," then it's fair to assume that you meant to say "open." We could have tested for that message explicitly, but why bother? This way, the user only has to remember one command instead of two.
From: someone
I hope I have got that right?, i really want to learn and understand the why!

Laurie gave you the answer to the looping behavior. The way your script was written in your first post, the block of commands following the if(message == "closen";) test set new values for offset and hi_end_open but it didn't do anything with them. The commands to llSetPrimitiveParams are all inside a block that only gets executed if message == "open." So, the script works if you say "open," but if you say "close" it does nothing until the next time you say "open."
From: someone
You have also added in a llToLower (I have never come across that one as yet, more reaserch on the wiki needed) and turned integer to ON and set that to 1, so it moves to the correct offset, just -1 rather than using ++i bit? which was very compliated (to my head anyway)

llToLower is a way to be kind to the user. It means that the key word "close" is not case sensitive. The user doesn't have to remember whether to type "close" or "CLOSE" or "Close."
Introducing the flag I called ON is simply a way for using the same block of llSetPrimitiveParams commands to open and close the curtains. It saves having to duplicate lines of code that differ from each other only in whether the offset is getting bigger or smaller with each iteration. Set ON=1 of the curtains are supposed to open and ON=-1 if they are supposed to close. You still have to step through multiple iterations by incrementing i each time.
From: someone
Thanks so much for helping me with this.

Also, can I ask why the listen messages dont work? is this in general or just in this script they were no use?

Well, llListenRemove tells the script to stop listening for more messages. You don't want that to happen, because you want to be able to say "open" or "close" lots of times. The only time you set up a new listen is in the state_entry event, so once you remove the listen handle, the script is deaf until you reset it. Bad idea.
From: someone
Thanks so much again for all of your help

NP. It's the way we all learn. :)
BTW, I never commented on it, but take a look at the value of hi_end_fixed that you set in your initial post. You gave it a value of -0.3, which would mess up the open/close behavior. The purpose of that variable is to move the top of the curtain up (or down) by exactly half the amount that the prim's size changes, so that the top of the curtain stays in one place. It has to be -0.5 for that to be true. That's why I changed it in my version of the script.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at