Help with Listen Event
|
Ozark Mayo
Registered User
Join date: 3 Jun 2008
Posts: 18
|
12-23-2009 16:37
I have been trying every way to figure out how to do this... I want to combine the following two separate scripts into one single script. integer inchan = 9 ; // Input channel integer bchan = -112300 ; // "Secret" channel/frequency message is sent on.
default { state_entry() { llListen(inchan,"","",""); // listens for just the owner, on channel 9 }
listen(integer chan, string name, key id, string mess) { if (id == llGetOwner()) { llRegionSay(bchan,llKey2Name(llGetOwner())+"> "+mess); llOwnerSay(llKey2Name(llGetOwner())+"> "+mess); llPlaySound("ce3ecb24-6fcc-701b-4110-5d12c2fd7396",1.0); } } }
AND integer inchan = 9 ; // Input channel integer bchan = -112300 ; // "Secret" channel/frequency message is sent on.
default { state_entry() { // llResetScript(); llListen(bchan,"","",""); // listens for just the owner, on channel 9 }
listen(integer chan, string name, key id, string mess) { llOwnerSay( name + "> " +mess); llPlaySound("ce3ecb24-6fcc-701b-4110-5d12c2fd7396",1.0); } }
Any help would be appreciated, Thank you.
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
12-23-2009 17:35
Simple solution:
integer inchan = 9 ; // Input channel integer bchan = -112300 ; // "Secret" channel/frequency message is sent on.
default { state_entry() { llListen(inchan,"","",""); llListen(bchan, "", "", ""); // listens for just the owner, on channel 9 }
listen(integer chan, string name, key id, string mess) { if(chan == inchan) { if (id == llGetOwner()) { llRegionSay(bchan,llKey2Name(llGetOwner())+"> "+mess); llOwnerSay(llKey2Name(llGetOwner())+"> "+mess); llPlaySound("ce3ecb24-6fcc-701b-4110-5d12c2fd7396",1.0); } } else if(chan == bchan) { llOwnerSay( name + "> " +mess); llPlaySound("ce3ecb24-6fcc-701b-4110-5d12c2fd7396",1.0); | } }
That's the simple, no thrills, get it done solution.. you can get a lot more fancy, adding other checks and stuff too.
|
Ozark Mayo
Registered User
Join date: 3 Jun 2008
Posts: 18
|
12-23-2009 17:50
I was thinking way more complex than just an else if.
I actually thought I needed two separate listen events.
Well, I guess we all have our dumb days heh. Or at least I do.
Thanks much!
|
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
|
12-23-2009 17:59
From: Ozark Mayo llListen(inchan,"","",""  ; // listens for just the owner, on channel 9 This could be a copy and paste error, but this llListen call will listen for anything and everything on inchan; to listen for just the owner you need to do this: llListen (inchan, "", llGetOwner (), ""  ;
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
12-23-2009 19:20
From: Ozark Mayo I actually thought I needed two separate listen events. you can't have more than one listen event, they all have to be handled in one place.  one event handler of each type per state, only.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
12-24-2009 22:59
My biggest pet peeve in scripting is the whole "","","" deal. Personally, I type "",NULL_KEY,"" because the middle is key, not a string. I know keys are a type of string, but it makes it that much more difficult for new scripters to understand the listen function and it's associated event handler. Is it really THAT difficult to type NULL_KEY ?
|
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
|
12-25-2009 01:50
"" is a lot less data than "00000000-0000-0000-0000-000000000000", which should not be forgotten if you're trying to write efficient scripts.
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
12-25-2009 04:28
difficult? no. a chunk of memory that isn't needed? yup. (worse is when people use NULL_KEY in link messages and they aren't using the key, which wastes memory on the sending AND receiving end)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
12-25-2009 05:28
According to Dari Caldwell, in her -- now full-rights -- collar scripts, declaring the following global variables is a good idea // Use this to reference null_key as a pointer. Surprisingly, this approach saves 2k per script. key null_key = NULL_KEY; // Also saves memory. string null_str = "";
I don't know enough to comment, I'm afraid.
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
12-25-2009 10:12
it has to do with the way variables are compiled and referenced constants that are declared are replaced at compile. but variables just get a pointer. so if a constant is standing by itself, it gets a whole variable container, which is larger than just a reference to a global variable. the trick here is that it's only helpful if you are using the constant in multiple places, so you replace several variables for several references to a single variable. the same applies to delared values in a script. so key gKeyNull = NULL_KEY; //-- one variable
default{ state_entry(){ llSetTexture( gKeyNull, 0 ); //-- there are only references to the variable llSetTexture( gKeyNull, 1 ); //-- they take up less space llSetTexture( gKeyNull, 2 ); llSetTexture( gKeyNull, 3 ); } }
is more efficient than default{ state_entry(){ llSetTexture( NULL_KEY, 0 ); //-- these will be converted at compile to the string llSetTexture( NULL_KEY, 1 ); //-- "00000000-0000-0000-0000-000000000000" llSetTexture( NULL_KEY, 2 ); //-- and take up separate space for each llSetTexture( NULL_KEY, 3 ); } }
or default{ state_entry(){ llSetTexture( "00000000-0000-0000-0000-000000000000", 0 ); //-- same problem llSetTexture( "00000000-0000-0000-0000-000000000000", 1 ); //-- each one takes llSetTexture( "00000000-0000-0000-0000-000000000000", 2 ); //-- up space seperately llSetTexture( "00000000-0000-0000-0000-000000000000", 3 ); } }
yes I know it's a contrived example, and some other language compilers automatically do this in the background, LSL doesn't.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
12-25-2009 11:18
Thanks, Void. That makes sense.
|