Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Touch-activated listen with a timer and a glow - particles won't shut off.

Sean Gorham
Stopped making sense
Join date: 5 Mar 2005
Posts: 229
04-23-2005 10:57
I realize touch-activated listens are nothing new, but I decided to make one from scratch as an experiment in learning LSL. I have a bracelet with a brunch of public scripts in it all hooked through a master listen (thanks, Brian Mifflin!), and decided to tweak it so the listen was on only if I touched the bracelet, and then only for a limited period.

My intent: touch the bracelet to activate the listen, start a timer, and turn on a simple particle glow (so I can easily tell it's still on). If I touch the bracelet again, the listen and glow shut off. If the timer runs out, do the same. If I give the bracelet a command, the listen processes it as usual, then resets the timer.

Here's what I've got so far in a test object. Apologies in advance for any sloppy code:

CODE
integer listen_channel = 24;
integer listen_handle;
integer timer_life = 10;
float particle_life = 5.0;
vector particle_color = <1,1,1>;

deactivate() {
llOwnerSay("Deactivating.");
llListenRemove(listen_handle);
llSetTimerEvent(0); // kill the timer
llResetScript(); // start from scratch
}

default
{
on_rez (integer param) {
llResetScript(); // make sure everything's kosher at the start
}

state_entry() {
llOwnerSay("Ready.");
llParticleSystem([]);
}

touch_start(integer total_number) {
llOwnerSay("Starting timer for " + (string)timer_life + " seconds.");
state active; // turn everything on!
}
}

state active {
state_entry() {
llParticleSystem([PSYS_PART_FLAGS, PSYS_PART_EMISSIVE_MASK|PSYS_PART_FOLLOW_SRC_MASK, PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_DROP, PSYS_PART_START_COLOR, particle_color, PSYS_PART_MAX_AGE, particle_life, PSYS_SRC_BURST_RATE, particle_life, PSYS_PART_START_SCALE, <2,2,2>]); // turn on the glow
listen_handle = llListen(listen_channel, "", llGetOwner(), "");
llSetTimerEvent(timer_life); // start the countdown
llOwnerSay("Activated.");
}

// shut down if the timer's run out
timer() {
llOwnerSay("Timer expired.");
deactivate();
state default; // go back to normal
}

listen(integer channel, string name, key id, string message) {
llOwnerSay("Message received: \"" + message + "\"");
if (message == "stop") {
deactivate();
state default;
} else {
llOwnerSay("Resetting timer.");
llSetTimerEvent(timer_life); // reset the countdown
}
}

// if the object is touched, shut down, even if the timer hasn't run out yet
touch_start(integer total_number) {
deactivate();
state default; // go back to normal
}
}


So far, it works, but for one hitch -- the @#$%! particle glow won't go away! Originally I was just using llParticleSystem() with an empty list to turn off the glow, as shown in the LSL wiki. This works, but only if I touch the bracelet. If the timer runs out, it won't turn off the glow. What's really confusing is both the listen and the touch_start in state activate call the same global function -- deactivate() -- but only the call from touch_start seems to work right.

I've tried moving the call to llParticleSystem() around, with no luck. (It was originally in deactivate().) On a suggestion from FlipperPA Peregrine I also stuck an llResetScript() in there. That didn't help either. Everything else seems to work OK, except for that glow. :p Suggestions on what I'm doing wrong, anyone?
_____________________
COOL GEAR BY GORHAM
Clothing, Animations, Gadgets and More!
Serpent Isle | Magenta | Manhunt Mall | Sylvina
SLBoutique | SL Exchange
Toy LaFollette
I eat paintchips
Join date: 11 Feb 2004
Posts: 2,359
04-23-2005 11:36
add this when turning the particles off
llParticleSystem( [] );
_____________________
"So you see, my loyalty lies with Second Life, not with Linden Lab. Where I perceive the actions of Linden Lab to be in conflict with the best interests of Second Life, I side with Second Life."-Jacek
Azreal Rubio
PrimHead
Join date: 29 Jan 2004
Posts: 194
04-23-2005 11:37
Hi you might need to stick this in your deactivate function /procedure / whatever.

CODE
llParticleSystem([]);


it will kill the current particle system running in that object, Particles are a property of an object (Or so I've been informed)
Sean Gorham
Stopped making sense
Join date: 5 Mar 2005
Posts: 229
04-23-2005 12:38
That's just it, though -- originally I did have the call to llParticleSystem in my deactivate() function, like so:

CODE
deactivate() {
llOwnerSay("Deactivating.");
llParticleSystem([]);
llListenRemove(listen_handle);
llSetTimerEvent(0); // kill the timer
}

It still didn't work.

But! That did lead me to a solution, so thanks for setting me on the path. I need both the call to llParticleSystem() and the call to llResetScript() in deactivate():

CODE
deactivate() {
llOwnerSay("Deactivating.");
llParticleSystem([]);
llListenRemove(listen_handle);
llSetTimerEvent(0); // kill the timer
llResetScript(); // start from scratch
}

If they're not both in there, the particles don't shut off. Confusing... Like I said, I figured this was a noobie question. :) Thanks for your help, everyone.
_____________________
COOL GEAR BY GORHAM
Clothing, Animations, Gadgets and More!
Serpent Isle | Magenta | Manhunt Mall | Sylvina
SLBoutique | SL Exchange
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
04-23-2005 14:20
Interesting discovery. I'd not have thought the reset to be necessary since the particle is a prim property.

/esc
_____________________
http://slurl.com/secondlife/Together
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
04-24-2005 03:11
I would have thought that either having llParticleSystem([]); in deactivate or in state_entry() for the default state should do it.

One other fix that *might* work - and one that would change your call to the deactivate function, would be to write a state_exit() event containing all the deactivate code and the particle system off line. state_exit() works nicely for such things, you use it just like you've used deactivate, but without calling a function. Try here.
Sean Gorham
Stopped making sense
Join date: 5 Mar 2005
Posts: 229
04-24-2005 10:02
It never even occurred to me there was a state_exit() function! So much to learn, but that's a good thing. I'll definitely give this a try -- I feel no need to reinvent the wheel. :D Thanks Eloise!

Edit: I just altered the code to use state_exit(). Works like a charm. Thanks again, Eloise. :)
_____________________
COOL GEAR BY GORHAM
Clothing, Animations, Gadgets and More!
Serpent Isle | Magenta | Manhunt Mall | Sylvina
SLBoutique | SL Exchange