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.
Suggestions on what I'm doing wrong, anyone?
Thanks for your help, everyone.
Thanks Eloise!