Difference between revisions of "Sensor"

From Second Life Wiki
Jump to navigation Jump to search
m (added an example)
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(26 intermediate revisions by 15 users not shown)
Line 1: Line 1:
{{LSL_Event
{{LSL_Event
|event_id=13|event_delay|event=sensor
|event_id=13|event_delay|event=sensor
|p1_type=integer|p1_name=num_detected|p1_desc
|p1_type=integer|p1_name=num_detected|p1_desc=number of objects/avatars found
|event_desc=Result of the [[llSensor]] library function call.
|event_desc=Results from a call to either [[llSensor]] or [[llSensorRepeat]].
|event_footnote=The results are ordered from nearest to furtherest.
|event_footnote=The results are ordered from nearest to furthest.
<br/>'''num_detected''' is always greater than zero, the [[no_sensor]] event is triggered if no objects/avatars were found.
|constants
|constants
|spec
|spec
|caveats
|caveats=*[[Linden]]s in [[God Mode|administrative mode]] cannot be sensed by sensors in the same region as the Linden.
|examples=Names people who are near an object.
*Sensors placed in attachments will use the direction the avatar is facing as their forward vector. In mouselook, this means that it will be wherever the avatar is looking, while out of mouselook, this means whichever way the avatar is pointing. This does not include where the avatar's head is pointing, or what animation the avatar is doing, just the direction the avatar would move in if you walked forward. This is the case, regardless of where the object is attached.
 
*A sensor running in an attachment will not detect the avatar wearing it.
<pre>
*A sensor will only return the first 16 objects/avatars found.
float range = 3.0; //  metres
*This event is not executed when nothing is detected, means, you never get the result 0 returned. Use [[no_sensor]] for that.
float interval = 5.0; // seconds
*on logout all avatars leave a Ghost for a few moments, this results in Failures in llDetected functions in sensor events.
 
|examples=
<source lang="lsl2">
default
default
{
{
     state_entry()
     touch_start(integer num_detected)
     {
     {
        llSensorRepeat("", "", AGENT, range, TWO_PI, interval); // activates the sensor.
    //  do a 10m spherical sweep
        // look for avatars (i.e. not moving objects) on all sides of the object
        llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME, 10.0, PI);
     }
     }


     sensor (integer numberDetected)
     sensor (integer num_detected)
     {
     {
         string msg = "Detected "+(string) numberDetected+" avatar(s): ";
         string message = "Detected " + (string)num_detected + " avatar(s): " + llDetectedName(0);
        integer i;
 
        msg += llDetectedName(0);
    //  we already added the first avatar above, so continue from index 1
         for (i = 1; i < numberDetected; i++)
         integer index = 1;
        {
        while (index < num_detected)
             msg += ", ";
             message += ", " + llDetectedName(index++);
            msg += llDetectedName(i);
 
        }
         llWhisper(PUBLIC_CHANNEL, message);
         llWhisper(0, msg);
     }
     }


     no_sensor()
     no_sensor()
     {
     {
         llWhisper(0, "Nobody is near me at present.");
         llWhisper(PUBLIC_CHANNEL, "Nobody is near me at present.");
     }
     }
}
}
</pre>
</source>
|helpers
|helpers
|also_header
|also_header
Line 47: Line 48:
|also_articles={{LSL DefineRow||{{LSLGC|Detected}}|}}
|also_articles={{LSL DefineRow||{{LSLGC|Detected}}|}}
|also_footer
|also_footer
|notes
|notes={{LSL Tip|You might want to use [[llGetAgentList]] instead of using sensors to get a list of all avatars within the same parcel or region.}}
|mode
|mode
|deprecated
|deprecated

Latest revision as of 01:09, 22 January 2015

Description

Event: sensor( integer num_detected ){ ; }

Results from a call to either llSensor or llSensorRepeat.

• integer num_detected number of objects/avatars found

The results are ordered from nearest to furthest.
num_detected is always greater than zero, the no_sensor event is triggered if no objects/avatars were found.

Caveats

  • Lindens in administrative mode cannot be sensed by sensors in the same region as the Linden.
  • Sensors placed in attachments will use the direction the avatar is facing as their forward vector. In mouselook, this means that it will be wherever the avatar is looking, while out of mouselook, this means whichever way the avatar is pointing. This does not include where the avatar's head is pointing, or what animation the avatar is doing, just the direction the avatar would move in if you walked forward. This is the case, regardless of where the object is attached.
  • A sensor running in an attachment will not detect the avatar wearing it.
  • A sensor will only return the first 16 objects/avatars found.
  • This event is not executed when nothing is detected, means, you never get the result 0 returned. Use no_sensor for that.
  • on logout all avatars leave a Ghost for a few moments, this results in Failures in llDetected functions in sensor events.
All Issues ~ Search JIRA for related Bugs

Examples

default
{
    touch_start(integer num_detected)
    {
    //  do a 10m spherical sweep
        llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME, 10.0, PI);
    }

    sensor (integer num_detected)
    {
        string message = "Detected " + (string)num_detected + " avatar(s): " + llDetectedName(0);

    //  we already added the first avatar above, so continue from index 1
        integer index = 1;
        while (index < num_detected)
            message += ", " + llDetectedName(index++);

        llWhisper(PUBLIC_CHANNEL, message);
    }

    no_sensor()
    {
        llWhisper(PUBLIC_CHANNEL, "Nobody is near me at present.");
    }
}

Notes

KBcaution.png Important: You might want to use llGetAgentList instead of using sensors to get a list of all avatars within the same parcel or region.

See Also

Functions

•  llSensor
•  llSensorRepeat

Articles

•  Detected

Deep Notes

Signature

event void sensor( integer num_detected );