LlSensor

From Second Life Wiki

Jump to: navigation, search

Contents

Summary

Function: llSensor( string name, key id, integer type, float range, float arc );
• string name
• key id
• integer type
• float range
• float arc

Examples

This sensor scans a 45 degree cone about the x-axis. (PI/2 or PI_BY_TWO scans a hemisphere. PI is a spherical scan.)

llSensor( "Gigs Taggart", NULL_KEY, AGENT_BY_LEGACY_NAME, 96.0, PI/4 );

This sensor detects all prims and agents with a given name within 15m of the sensor. (AGENT, PASSIVE and ACTIVE behave inclusively. SCRIPTED is not inclusive and will exclude non-scripted targets (like avatars) from the detected set.)

llSensor( "", NULL_KEY, ( AGENT_BY_LEGACY_NAME | PASSIVE | ACTIVE ), 15.0, PI );

Basic example script that when touched executes a sensor scan of agents. When the sensor event is processed it spits out messages to the owner of each detected agents' name.

default
{
    touch_start(integer total_number)
    {
        llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME, 30.0, PI);
    }
 
    sensor( integer detected )
    {
        while(detected--)
        {
            llOwnerSay(llDetectedName(detected));
        }
    }
}

Notes

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

Loops & Repetition

Using llSensor in a for loop is a beginners mistake, as events will not interrupt each other (the sensor event will not interupt whatever event is currently being executed). To perform repeat sensor sweeps, llSensorRepeat is the better solution. While it is possible to call llSensor from a timer event, it is less efficient to do so; there is a limit to the number of events that can be processed in a second and using the timer just to call llSensor will result in your script getting less timeslice.

See Also

Events

•  sensor Triggered when a sensor detects something
•  no_sensor Triggered when a sensor detects nothing

Functions

•  llSensorRepeat Runs a sensor on a timer
•  llSensorRemove Stops the llSensorRepeat timer

Deep Notes

Search JIRA for related Issues

This article wasn't helpful for you? Maybe the related article at the LSL Wiki is able to bring enlightenment.
Personal tools
In other languages