Talk:LlSensorRemove
Remove no_sensor() from example
Someone correct me if I'm wrong, but I don't think the example needed its no_sensor() event, since it was just setting up exactly the same repeating sensor that would fire anyway. It looks like a copy/paste mistake of a script that would normally use a regular llSensor() call.
Here it is in case I've missed something: <lsl> default {
state_entry()
{
llSensorRepeat("", "", AGENT, 5, PI, 1); //Searches the agent in the range. 5 is the range (in meters).
}
sensor(integer num_detected)
{
llOwnerSay("Detected to: "+llKey2Name(llDetectedKey(0))); //Detects the name of the agent.
llSensorRemove(); //Removes the sensor.
//This does the sensor search for an agent once.
}
no_sensor()
{
llSensorRepeat("", "", AGENT, 5, PI, 1);
//If agent is not in range of sensor, this will search the agent again.
}
}
</lsl>
-- Haravikk (talk|contribs) 10:03, 14 September 2012 (PDT)
- We both will need correcting, I agree with you. At first I thought it was an example that was intended to use llSensor and not llSensorRepeat but then having the no_sensor event would essentially turn it into a llSensorRepeat with llSensorRemove in the sensor statement (which it has). It looks like whoever upgraded the script forgot or didn't think to remove the no_sensor event. -- Strife (talk|contribs) 11:59, 14 September 2012 (PDT)
- It's actually kind of weird as an example in general, and a 1 second sensor repeat doesn't make for good practice. I'm thinking maybe it could do with a more real-world example like a simple touch-to-scan:
<lsl>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 = llKey2Name(id);
// 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;
}
}</lsl>Maybe a bit much, but the current example doesn't really fit in with any really useful applications, as a 1 second sensor repeat that only terminates when someone passes within 5m is a bit odd. Plus I think the examples need to have as much good-practice as possible since so many scripters copy/paste them :)
-- Haravikk (talk|contribs) 12:37, 14 September 2012 (PDT)