"looping" functions within listen event
|
Damien Korolev
Registered User
Join date: 24 Apr 2009
Posts: 3
|
01-27-2010 15:38
Hello all. I'm a beginner in lsl so this will probably be blindingly simple (too all but me), but I'm having trouble working out how to "loop" functions under the listen event.
I am trying to create an object that, upon hearing "red alert", changes to a dark then lighter shade of red repeatedly, until told otherwise. The functions go:
llSetColor(<0.5,0.0,0.0>,ALL_SIDES); llSleep(0.3); llSetColor(<1.0,0.0,0.0>,ALL_SIDES); llSleep(0.3);
If it were state_entry I'd just lash in llResetScript, but of course that'll reset the entire script.
Is there a function or method that would have the effect of making these functions repeat over and over?
Thanks, and sorry if this is covered already, I had a look but couldn't find anything similar.
Damien
|
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
|
01-27-2010 15:49
I'll probaly get a severe beating for suggesting a 0.3 second timer event using a global variable toggle... integer DARK; then in the listen event... if (message == "red alert"  { llSetTimerEvent (0.3); } else if (message == "stand down"  { llSetTimerEvent (0.0); } and in the timer event... DARK = !DARK; llSetColour (<0.5 + (float) DARK / 2.0, 0.0, 0.0>, ALL_SIDES); ETA: you'll probably need to set the object to dark red in reponse to the "stand down" message too.
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-27-2010 15:56
One severe beating, coming right up. I'd suggest instead using a two-frame texture (one frame light red and the other dark red) and then animating the texture with
llSetTextureAnim( ANIM_ON | LOOP, ALL_SIDES, 2, 1, 1, 2, 3.0 );
That won't stress the sim with a fast timer, and it's REAL easy to do.
_____________________
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 
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
01-27-2010 15:56
Try this (I can't claim credit for the method of switching the colours, but I really like it). In general for this sort of thing, a timer is best. I would only use llSleep() if I am sure I really want to hibernate the script. vector colour1 = <0.5,0.0,0.0>; vector colour2 = <1.0,0.0,0.0>; vector colour;
float t = 0.3;
default{ state_entry(){ colour = colour2; llSetColor(colour,ALL_SIDES); llListen(9,"", llGetOwner(),""); } listen(integer channel, string name, key id, string message){ if(llToLower(message)=="on"){ colour = colour1+colour2-colour; llSetColor(colour,ALL_SIDES); llSetTimerEvent(t); } else if (llToLower(message)=="off"){ colour = colour2; llSetTimerEvent(0.0); } } timer(){ colour = colour1+colour2-colour; llSetColor(colour,ALL_SIDES); } }
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-27-2010 16:21
just to be funny........ (because I like Rolig's solution) integer gBooAlert; integer gIntSwp;
default{ state_entry(){ llListen( 0, "", "", "" ); }
listen( integer vIntNul, string vStrNul, key vKeyNul, string vStrCmd ){ integer vIdxTst = llListFindList( ["red alert!", "stand down"], (list)vStrCmd ); if (~vIdxTst){ if (vIdxTst){ gBooAlert = FALSE; }else{ gBooAlert = TRUE; string object_name = llGetObjectName (); llSetObjectName ("Mr. Spock" ; llSay (PUBLIC_CHANNEL, "Red alert? I can't believe my ears, Captain!" ; llSetObjectName ("Captain Kirk" ; llSay (PUBLIC_CHANNEL, "Well I can't believe your ears either, Mr. Spock." ; llSetObjectName (object_name); } llSetColor( ZERO_VECTOR, -1 ); //-- default black } }
changed( integer vBitChg ){ if (gBooAlert){ llSetColor( < (float)(gIntSwp = !gIntSwp), 0.0, 0.0 >, -1 ); //-- flash red/black } } }
timers, we don't need no stinking timers! note: I have no clue if a scripted color change will actually trigger the changed event, but it should. ETA: logical not won't accept floats... and I liked pete's suggestion.... works nicely now
_____________________
| | . "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... | - 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-27-2010 16:34
Hmmm... Your line llSetColor( < gFltSwp = !gFltSwp, 0.0, 0.0 >, -1 ); //-- flash red/black kicks up a compile error (Yes, I fixed gFltSwap). I don't see why, offhand. Here's mine. It works like a dream.... default { state_entry() { llSetTexture("75bd2f5b-116e-41f5-b0c0-1abf655d6e0c",ALL_SIDES); llSetTextureAnim( ANIM_ON | LOOP, ALL_SIDES, 2, 1, 1, 2, 3.0 ); } }
_____________________
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 
|
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
|
01-27-2010 16:35
From: Void Singer just to be funny........ (because I like Rolig's solution) integer gBooAlert; float gFltSwp;
default{ state_entry(){ llListen( 0, "", "", "" ); }
listen( integer vIntNul, string, vStrNul, key vKeyNul, string vStrCmd ){ integer vIdxTst = llSubStringIndex( "red alert! stand down", vStrCmd ); if (~vIdxTst){ if (vIdxTst){ gBooAlert = FALSE; }else{ gBooAlert = TRUE; string object_name = llGetObjectName (); llSetObjectName ("Mr. Spock" ; llSay (PUBLIC_CHANNEL, "Red alert? I can't believe my ears, Captain!" ; llSetObjectName ("Captain Kirk" ; llSay (PUBLIC_CHANNEL, "Well I can't believe your ears either, Mr. Spock." ; llSetObjectName (object_name); } llSetColor( ZERO_VECTOR, -1 ); //-- default black } }
changed( integer vBitChg ){ if (gBooAlert){ llSetColor( < gFltSwap = !gFltSwp, 0.0, 0.0 >, -1 ); //-- flash red/black } } }
timers, we don't need no stinking timers! note: I have no clue if a scripted color change will actually trigger the changed event, but it should. Fixed it for ya.
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-27-2010 16:49
From: Pete Olihenge Fixed it for ya. score =)
_____________________
| | . "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... | - 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-27-2010 16:54
Ah... Found it. if gFltSwp is typed as float, you can't use it as a T/F switch. You need to set it as a global integer variable and then write changed( integer vBitChg ){ if (gBooAlert){ float a = (float)(gFltSwp = !gFltSwp); llSetColor( < a, 0.0, 0.0 >, -1 ); //-- flash red/black } }
That compiles OK. Unfortunately, however, the script doesn't work. It looks like you can't trigger a change event this way.
_____________________
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 
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-27-2010 17:01
From: Rolig Loon Ah... Found it. if gFltSwp is typed as float, you can't use it as a T/F switch. You need to set it as a global integer variable and then write changed( integer vBitChg ){ if (gBooAlert){ float a = (float)(gFltSwp = !gFltSwp); llSetColor( < a, 0.0, 0.0 >, -1 ); //-- flash red/black } }
That compiles OK. Unfortunately, however, the script doesn't work. It looks like you can't trigger a change event this way. it works in the above correction... I also changed the phrase detection to be more discriminating.... there was also an extra comma in the listen
_____________________
| | . "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... | - 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-27-2010 17:05
Nice! 
_____________________
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 
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-27-2010 17:09
oh yeah, I guess someone should explain to the OP exactly why you shouldn't use the method I wrote...
_____________________
| | . "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... | - 
|
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
|
01-27-2010 17:18
Miss! Miss! Miss! I know the answer, Miss!
Using llListen( 0, "", "", "" ); is a practice that's perhaps even more evil than using a limited-duration sub-five-second timer event!
Am I right, Miss?
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-27-2010 17:24
well a filtered listen would be nice... but uh... no..... (do you have any idea how much trafic in prim updates a single unclocked looped prim mod does? I was thinking of doing one that exapnaded a prim outside of the other too... but that's even worse since it plays holy hell with physics too)
_____________________
| | . "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... | - 
|
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
|
01-27-2010 17:40
Ah ha! So in spite of the fun and games I've learned several useful lessons here today, and from what seemed a fairly straightforward question, too. Damn, I *will* miss this forum if it goes.
|
Paladin Pinion
The other one of 10
Join date: 3 Aug 2007
Posts: 191
|
01-27-2010 20:21
From: Void Singer llSetColor( < a, 0.0, 0.0 >, -1 ); //-- flash red/black
That's damned sneaky. I like it.
_____________________
Mote Particle Script Generator - easier and faster than any HUD Also: Paladin's Sunbeam. Up at dawn, gone by dusk, day and night sounds, fully configurable See more at: www.paladinpinion.com
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-27-2010 21:01
just a matter of lookin at the values you want, and the easiest way to get them... or similar one's if that's easier...
_____________________
| | . "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... | - 
|
Damien Korolev
Registered User
Join date: 24 Apr 2009
Posts: 3
|
01-28-2010 04:22
From: Innula Zenovka Try this (I can't claim credit for the method of switching the colours, but I really like it). In general for this sort of thing, a timer is best. I would only use llSleep() if I am sure I really want to hibernate the script. vector colour1 = <0.5,0.0,0.0>; vector colour2 = <1.0,0.0,0.0>; vector colour;
float t = 0.3;
default{ state_entry(){ colour = colour2; llSetColor(colour,ALL_SIDES); llListen(9,"", llGetOwner(),""); } listen(integer channel, string name, key id, string message){ if(llToLower(message)=="on"){ colour = colour1+colour2-colour; llSetColor(colour,ALL_SIDES); llSetTimerEvent(t); } else if (llToLower(message)=="off"){ colour = colour2; llSetTimerEvent(0.0); } } timer(){ colour = colour1+colour2-colour; llSetColor(colour,ALL_SIDES); } }
I used this one, as it was the most decipherable to my ignorant self. It's working a treat, cheers! Plus I have a few alternate examples to go through at my leisure! Cheers everyone.
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-28-2010 04:45
From: Damien Korolev I used this one, as it was the most decipherable to my ignorant self. It's working a treat, cheers!
Plus I have a few alternate examples to go through at my leisure! Cheers everyone. please please please don't use mine.... seriously....
_____________________
| | . "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... | - 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-28-2010 05:38
And please do take another serious look at the one I proposed (post #6). Not only is it a very short bit of code, it operates with minimal load on the sim and is less likely to add to lag problems for avatars in the area. I even uploaded the the two-color texture that you need to make it run. Its UUID is right in the script. Whenever you can avoid using a fast timer for something as simple as a flashing light, a marquee, or whatever, I strongly recommend doing 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 
|
Damien Korolev
Registered User
Join date: 24 Apr 2009
Posts: 3
|
01-28-2010 05:48
From: Void Singer please please please don't use mine.... seriously.... Ha ha! No worries, I saw your later post clarifying that. From: Rolig Loon And please do take another serious look at the one I proposed (post #6). Not only is it a very short bit of code, it operates with minimal load on the sim and is less likely to add to lag problems for avatars in the area. I even uploaded the the two-color texture that you need to make it run. Its UUID is right in the script. Whenever you can avoid using a fast timer for something as simple as a flashing light, a marquee, or whatever, I strongly recommend doing it. I didn't notice the UUID there(not that the absence of one would have prevented me from trying it out). I'll be giving that a go, nice one!
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-28-2010 06:54
Incidentally, if you'd prefer to have the blinking switchable, so you can turn the flash on or off, you can do it this way, still using the animated texture approach. float Red = 1.0; // The "Non-blinking" red color. Set to 1.0 for Dark Red, -1.0 for Light Red integer ON;
default { state_entry() { llSetPrimitiveParams([PRIM_TEXTURE,ALL_SIDES, "75bd2f5b-116e-41f5-b0c0-1abf655d6e0c",<0.5,1,1>,<-0.25*Red,0,0>,0.0]); }
touch_start(integer num) { ON = !ON; if (ON == TRUE) { llSetTextureAnim( ANIM_ON | LOOP, ALL_SIDES, 2, 1, 1, 2, 3.0 ); } else { llSetTextureAnim(FALSE,ALL_SIDES,1,1,1,1,1); llSetPrimitiveParams([PRIM_TEXTURE,ALL_SIDES, "75bd2f5b-116e-41f5-b0c0-1abf655d6e0c",<0.5,1,1>,<-0.25*Red,0,0>,0.0]); } } }
_____________________
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 
|