Jump to content

Sensor On Off Switch - help please


Loki Eliot
 Share

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

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

Recommended Posts

So far this forum has been unbelievably helpful, Kudos to everyone whos been so kind so far in helping me :)

My HUD is almost done, the last thing i'm trying to do is add a switch to switch the sensor on and off. I thought i had it done with the script below but sometimes the Sensor does not switch off.

Is there something i should be adding to the 'off state'  to make sure the sensor switches off properly?

 

default
{
    state_entry()
    {
        llSensorRepeat("", NULL_KEY, AGENT | ACTIVE | PASSIVE | SCRIPTED,8.0, PI,10.0);
        llOwnerSay("Sensor initialised...");
        llSetAlpha(100, ALL_SIDES);
    }
        sensor(integer num_detected)
    {
        integer i;
        for(i = 0; i < num_detected; i++)
        {
            if ((string)llDetectedName(i) == "bashable")
        {         
         llWhisper(3,"object" );
         }
    }
}
    touch_start(integer total_number) // another event with only one function inside
    {
        state off; // sets the script to a new "state" and starts running "state off"
    }
}
state off // a second state besides "default"
{
    state_entry() // this is run as soon as the state is entered
    {
        llOwnerSay("Sensor off...");
        llSetAlpha(0, ALL_SIDES);
    }
    touch_start(integer total_number)
    {
        state default;
    }
}

 

Link to comment
Share on other sites

Hmm that's strange indeed, since on a state change a repeating sensor should be released. Are you sure it changes the state (you have a llOwnerSay there)?Could it be that you have another script that causes the effect?

Just a very small thing: you don't need the (string) in (string)llDetectedName(i) == "bashable"

Link to comment
Share on other sites

Simply taking it off and on again will not change the state - did you expect it to? I.e. if you are in 'scan mode' and take the HUD off, it will still be in 'scan mode' if you put it on again.

I'm not sure about teleporting.

Does that help?

If not, exactly describe the situations that you deem strange

Link to comment
Share on other sites

here is a fast fixor



integer on;
default
{
    state_entry()
    {
      
    }
        sensor(integer num_detected)
    {
        integer i;
        for(i = 0; i < num_detected; i++)
        {
            if ((string)llDetectedName(i) == "bashable")
        {        
         llWhisper(3,"object" );
         }
    }
}
    touch_start(integer total_number)
    {
  if(on)
      {
          on = FALSE;
        llOwnerSay("Sensor off...");
        llSetAlpha(0, ALL_SIDES);
        llSensorRemove( );
          
        }
        else
        {
        on = TRUE;
        llOwnerSay("Sensor initialised...");
        llSetAlpha(100, ALL_SIDES);
       llSensorRepeat("", NULL_KEY, AGENT | ACTIVE | PASSIVE | SCRIPTED,8.0, PI,10.0);
           
  }
   }
    }

  • Like 1
Link to comment
Share on other sites

yup, always Always ALWAYS use *_end, if you can help it, and definitely NEVER call a state changge from *_start or the repeating portion of the event.

also it's best NOT to use different states at all unless you are controlling what events can be triggered (sensor is one of those special cases, because script calls only can control it)

also be aware that there are conditions where sensor repeat without a no_sensor event may be flaky, and sensor repeat is flaky with region borders, detecting across them seemingly random insane ways (there is a pattern)... sensor called from a timer is much more stable and predictable (detecting only in the same region)

Link to comment
Share on other sites

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