Difference between revisions of "Talk:LlSensorRemove"

From Second Life Wiki
Jump to: navigation, search
(Remove no_sensor() from example)
 
Line 4: Line 4:
  
 
Here it is in case I've missed something:
 
Here it is in case I've missed something:
<lsl>   no_sensor()
+
<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);
 
         llSensorRepeat("", "", AGENT, 5, PI, 1);
 
         //If agent is not in range of sensor, this will search the agent again.
 
         //If agent is not in range of sensor, this will search the agent again.
     }</lsl><br/>-- '''[[User:Haravikk_Mistral|Haravikk]]''' <sup><small>([[User_talk:Haravikk_Mistral|talk]]|[[Special:Contributions/Haravikk_Mistral|contribs]])</small></sup> 10:03, 14 September 2012 (PDT)
+
     }
 +
}
 +
</lsl><br/>-- '''[[User:Haravikk_Mistral|Haravikk]]''' <sup><small>([[User_talk:Haravikk_Mistral|talk]]|[[Special:Contributions/Haravikk_Mistral|contribs]])</small></sup> 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. -- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 11:59, 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. -- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 11:59, 14 September 2012 (PDT)
Line 50: Line 65:
  
 
:Sounds good to me. Maybe llDetectedName instead of llKey2Name? -- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 16:32, 14 September 2012 (PDT)
 
:Sounds good to me. Maybe llDetectedName instead of llKey2Name? -- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 16:32, 14 September 2012 (PDT)
 +
 +
::Okay, I've switched that in, along with a simpler usage example, and copied the old script in at the top of the page. <br/>-- '''[[User:Haravikk_Mistral|Haravikk]]''' <sup><small>([[User_talk:Haravikk_Mistral|talk]]|[[Special:Contributions/Haravikk_Mistral|contribs]])</small></sup> 03:49, 15 September 2012 (PDT)

Latest revision as of 02:49, 15 September 2012

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)

Sounds good to me. Maybe llDetectedName instead of llKey2Name? -- Strife (talk|contribs) 16:32, 14 September 2012 (PDT)
Okay, I've switched that in, along with a simpler usage example, and copied the old script in at the top of the page.
-- Haravikk (talk|contribs) 03:49, 15 September 2012 (PDT)