Jump to content

llSensorRepeat - more elegant way of doing this?


Postmark Jensen
 Share

You are about to reply to a thread that has been inactive for 4168 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I needed an object to detect an avatar walking by and sending a particle at them, one time only.  This works but seems like there would be a more elegant way than my hack.:

 

//SNIP all the particle code

default
{
    state_entry(){
        llSetTimerEvent(1);
    }
    
    sensor (integer num_detected){
    //llSay(0,"sensed");
    av_key = llDetectedKey(0);
    if (old_key != av_key)
        MyParticle(av_key);
    old_key = av_key;
    }
    
    no_sensor(){
        old_key = av_key = NULL_KEY;
    }
    timer() {
        llSensor("", NULL_KEY, AGENT, 9, PI);    
    }
    
}

  A little help please?  I left SL for a few years and am getting back on my feet again with LSL and building, so would love some input to help better me as a creator :)

 

-Postmark

Link to comment
Share on other sites

Running a timer with a 1 second pulse for something like this contributes to sim lag, albeit in a small way.  If you want to zap a person who comes within 9m of your object, you could just lay down a prim with a 9m radius and use a collision detector instead.  Also, as written, only one person gets zapped if two or more people are detected at once.  And that person could get zapped more than once if s/he isn't still closest to the detector the next time it fires.  It might be better to check a list that gets cleared periodically. Your code could look something like this.

list gZapped;   //Remember to make any "checked" variable or list like this globaldefault{    collision_start(integer num)    {        llSetTimerEvent(60.0);    // Clear the list after a minute        while(~num)        {            if(!~llListFindList(gZapped,[llDetectedKey(num)])            {                gZapped += [llDetectedKey(num)];                MyParticle(llDetectedKey(num));            }            --num;        }    }    timer()    {        llSetTimerEvent(0.0);        gZapped = [];    }}

 A collision_start event should only fire once, as long as your target is still on the detector, but you can't count on that. This code should still only fire the particle at your target one time even if he jumps up and down on the detector for a while.

 

Link to comment
Share on other sites

Thanks!  You're missing a close paren here:

if(!~llListFindList(gZapped,[llDetectedKey(num)])

 and unfortunately the code resets llSetTimerEvent everytime someone steps on it, but after using you code I relalized that I only want the particle script fired once, and using a prim on the ground with collision_start allows me to "raise" a skeleton particle from the ground.  It's far more creepy that just shooting one at the target :)  Thanks for the help and I'm definately going to use your code for a few traps around the land!

 

-Postmark

Link to comment
Share on other sites

Ooops.  Sorry about the missing paren.  That's the hazard of typing directly into the forums instead of into an editor.  Glad you caught it.

As for resetting the timer each time a person steps on the detector, that was intentional.  Doing it this way guarantees that the list remains alive as long as nobody has stepped on the detector within the past minute.  It's the equivalent of the no_sensor event in your initial script.  The list resets 60 seconds after the last person steps on the prim.  If you want to make it so that a person who returns within that minute also gets zapped, that's a trickier proposition.  You could do something like saving each person's UUID and collision time, and then removing only that person from the list after, say, 20 seconds.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4168 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...