LSL Wiki Mirror 7-7-7 : sensor

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings ::
sensor(integer num_detected)

This event is raised whenever objects matching the constraints of the llSensor or llSensorRepeat functions are detected. The number of detected objects is passed to the script in num_detected. Information on those objects may then be gathered via the llDetected* library functions.

If no matches are found, no_sensor will be raised instead.

The sensor() event handler will receive a maximum of 16 detected objects within 96m, sorted by target distance.

It seems that avatars in vehicles can be detected up by a sensor from very far distances. The most I've ever seen was over 1,000m away! -SchitsoMonkey

In the following example, clicking the object causes it to scan once for the presence of agents within a radius of 10m in all directions. If any agents are detected, the object whispers their names in order:

Example:
default
{
    touch_start(integer total_number)
    {
        llSensor("", NULL_KEY, AGENT, 10, PI); // scan for agents/avatars within 10 metres.
    }

    sensor(integer total_number) // total_number is the number of avatars detected.
    {
        llWhisper(0, (string)total_number + " avatars detected" );
        // The following 'for' loop runs through all detected avatars and says "Hello Jane Doe",
        // where "Jane Doe" is the name of the current detected avatar.
        integer i;
        for (i = 0; i < total_number; i++)
        {
            llWhisper(0, "Hello " + llDetectedName(i));
        }
    }
    
    // if nobody is within 10 meters, say so.
    no_sensor() {
        llSay(0, "Nobody is around.");
    }
}

Q: Do sensor areas overlapping simulator boundaries carry over into the other simulator(s)? Are they supposed to?
A: Not in all cases. As of 1.11 or so, llSensor does not detect across sim boundaries at all and llSensorRepeat is limited by only detecting across boundaries approximately every five seconds.

Q: Can a sensor detect child prims within the object that contains the sensor?
A: No. Sensors only detect the root prim in a linkset, and never the object containing the sensor itself. This is a good thing, as otherwise it would be possible to reverse-engineer linked objects and recreate them, completely negating asset permissions.
Likewise, sensors contained within attachments cannot be used to detect the agent to which the attachment is attached.

Q: Is there a way to just check whether an agent is within a sim?
A: Yes. Assuming you know the agent's key, you can use llKey2Name. No sensor is required. If you don't know the key.

Q: Is there a way to get a list of all agents within a sim?
A: No, not without many objects containing sensors and a fairly elaborate communications system. There isn't a way to just get a list.

Q: Where is the sensors origin in link sets?
A: A sensors point of origin in linked objects is from the prim calling the function. Not the root or the center of the linkset.

Q: How to detect more than 16 results in the area? Can i filter the results of 'first sensor' to find 16 different results with a 'second sensor'?

Events | Functions | Sensors
There are 10 comments on this page. [Display comments/form]