Jump to content

llSensorRepeat stops in a state change


Rolig Loon
 Share

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

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

Recommended Posts

This is probably common knowledge, but there's no mention of it the LSL wiki and I just discovered it by accident.   Compare these two scripts.

Script One:

default
{
    state_entry()
    {
        llSay(0, "In state default.");
    }
    
    touch_end(integer num)
    {
        llSetTimerEvent(1.0);
    }
    
    timer()
    {
        llSensor("","",AGENT_BY_LEGACY_NAME,3.0,PI);
    }
    
    sensor(integer num)
    {
        llSay(0,"Detected.  Changing state.");
        state new;
    }
}

state new
{
    state_entry()
    {
        llSay(0,"In new state.");
    }
    
    touch_end(integer num)
    {
        state default;
    }
}

 Script Two:

default
{
    state_entry()
    {
        llSay(0, "In state default.");
    }
    
    touch_end(integer num)
    {
        llSensorRepeat("","",AGENT_BY_LEGACY_NAME,3.0,PI, 1.0);
    }
    
    sensor(integer num)
    {
        llSay(0,"Detected.  Changing state.");
        state new;
    }
}

state new
{
    state_entry()
    {
        llSay(0,"In new state.");
    }
    
    touch_end(integer num)
    {
        state default;
    }
}

 They should both accomplish the same thing.  Script One does it with a timer that fires llSensor once a second, and Script Two does it with llSensorRepeat, also firing once a second.  As I expected, both scripts stop sensing anything when execution is tossed to state New.  It surprises me, though, that Script One begins detecting again when I touch it to send execution back to state default, but Script Two does not.  In other words, a timer event and llSensorRepeat both stop when you change states, but a timer event restarts when you come back.  llSensorRepeat doesn't.

That's useful information, but I never knew that.  Did anyone else?  Or is something else happening here that I am not understanding?

 

Link to comment
Share on other sites

Thanks, Rolig.  I hadn't realised that about llSensorRepeat. 

The timer doesn't stop and restart, though.   The reason it looks like that is that, in your example,  there's no timer event in state new, so nothing happens, but, in reality, it never stops firing.

Try

default{    state_entry()    {        llSay(0, "In state default.");    }        touch_end(integer num)    {        llSetTimerEvent(1.0);    }        timer()    {        llSensor("","",AGENT_BY_LEGACY_NAME,3.0,PI);    }        sensor(integer num)    {        llSay(0,"Detected.  Changing state.");        state new;    }}state new{    state_entry()    {        llSay(0,"In new state.");    }        timer(){        llOwnerSay("timer event firing in new state");    }        touch_end(integer num)    {        state default;    }}

 

Link to comment
Share on other sites

I wondered about that, Innula.  It's been a while since I experimented with timers across states, and I don't remember whether I convinced myself that it was the same timer in two states, or two different timers.  I see now that it's apparently it's the same one, though.  If you change its speed when you enter state New, the timer keeps firing at the new speed when you return to state default.  It doesn't go back to the original speed.  Curiouser and curiouser.  That makes it all the odder that a timer can persist across states but llSensorRepeat doesn't.

Link to comment
Share on other sites

No.  The point is that the llSensorRepeat has stopped when you return to state default.  That is unlike the timer, which does not stop.  (But I did try putting a sensor event in state New anyway, just for completeness.  As you might expect, it does nothing.)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3677 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...