Difference between revisions of "LlSensorRemove"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
Line 10: Line 10:
|constants
|constants
|examples=The following basic example shows an object that when touched starts scanning for avatars in 10m every 30 seconds, and stops as soon as at least one is found, and returns their name.
|examples=The following basic example shows an object that when touched starts scanning for avatars in 10m every 30 seconds, and stops as soon as at least one is found, and returns their name.
<lsl>default {
<source lang="lsl2">default {
     touch_start(integer x) {
     touch_start(integer x) {
         llSensorRepeat("", NULL_KEY, AGENT, 10.0, PI, 30.0);
         llSensorRepeat("", NULL_KEY, AGENT, 10.0, PI, 30.0);
Line 23: Line 23:
         llSensorRemove();
         llSensorRemove();
     }
     }
}</lsl>
}</source>
The next script is a more real-world example of a scanner that when touched will begin listing avatar names and distances, but will stop if no avatars are detected. It demonstrates the use of [[llSensor]]() when starting the scan, to avoid the initial delay of an [[llSensorRepeat]]() call.
The next script is a more real-world example of a scanner that when touched will begin listing avatar names and distances, but will stop if no avatars are detected. It demonstrates the use of [[llSensor]]() when starting the scan, to avoid the initial delay of an [[llSensorRepeat]]() call.
<lsl>integer scanning = FALSE;
<source lang="lsl2">integer scanning = FALSE;
default {
default {
     touch_start(integer x) {
     touch_start(integer x) {
Line 59: Line 59:
         scanning = FALSE;
         scanning = FALSE;
     }
     }
}</lsl>
}</source>
|helpers
|helpers
|also_functions=
|also_functions=

Revision as of 14:45, 22 January 2015

Summary

Function: llSensorRemove( );

Removes the sensor setup by llSensorRepeat.

There are no parameters or return value for this function, as only one llSensorRepeat can be specified per script.

Caveats

  • If called within the sensor event then it also removes all of the sensor data that is accessed by the detection functions.
All Issues ~ Search JIRA for related Bugs

Examples

The following basic example shows an object that when touched starts scanning for avatars in 10m every 30 seconds, and stops as soon as at least one is found, and returns their name.

default {
    touch_start(integer x) {
        llSensorRepeat("", NULL_KEY, AGENT, 10.0, PI, 30.0);
    }

    sensor(integer x) {
        key id = llDetectedKey(0);
        string name = llGetDisplayName(id);
        if (("" == name) || ("???" == name)) name = llDetectedName(0);

        llSay(PUBLIC_CHANNEL, name + " was found first!");
        llSensorRemove();
    }
}

The next script is a more real-world example of a scanner that when touched will begin listing avatar names and distances, but will stop if no avatars are detected. It demonstrates the use of llSensor() when starting the scan, to avoid the initial delay of an llSensorRepeat() call.

integer scanning = FALSE;
default {
    touch_start(integer x) {
        llSensor("", NULL_KEY, AGENT, 10.0, PI); // Start the scan
    }
 
    sensor(integer x) {
        string text = ""; vector myPos = llGetPos();
        // Loop through avatars from furthest to nearest
        while ((--x) >= 0) {
            key id = llDetectedKey(x);
 
            // Get display name, or use legacy name as a fallback
            string name = llGetDisplayName(id);
            if (("" == name) || ("???" == name)) name = llDetectedName(x);
 
            // Add distance to the name
            name += " (" + (string)((integer)llVecDist(myPos, llDetectedPos(x))) + "m)";
            if (text) name = "\n" + name;
            text += name;
        }
        llSetText(text, <1.0, 1.0, 1.0>, 1.0);
 
        if (!scanning) {
            // Repeat the scan every 30 seconds
            llSensorRepeat("", NULL_KEY, AGENT, 10.0, PI, 30.0);
            scanning = TRUE;
        }
    } no_sensor() {
        // No avatars nearby, lets turn off the scan
        llSetText("", ZERO_VECTOR, 0.0);
        llSensorRemove();
        scanning = FALSE;
    }
}

See Also

Events

•  sensor

Functions

•  llSensorRepeat Scans for agents or objects every time period

Deep Notes

Search JIRA for related Issues

Signature

function void llSensorRemove();

Haiku

Call off the hounds.
The quarry has escaped us.
Back to the stables.