Jump to content

Sensor


Shihan Feiri
 Share

You are about to reply to a thread that has been inactive for 4662 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm trying to set range sensor in one mine project but i miss something here. If someone can say where error is in script...

//Script need to check if defined user wich key is in object descripton is in range

integer on;
string user;

default
{
    state_entry()
    {
      
    }
        sensor(integer num_detected)
    {
        integer i;
        string user;
        user =llGetObjectDesc();
        for(i = 0; i < num_detected; i++)
        {
            if (llDetectedKey(0)!= user)// If user leave out of rage
        {        
         llShout(0,"Good bye" + (string)user);// Shout is just for test purpose
         }  
         else if(llDetectedKey(0)== user)
         {
             llSay(0,"Welcome user"); // In fact this part is for test only . It will not say anything in working mode
             }
    }
}
    touch_start(integer total_number)
    {
  if(on)
      {
          on = FALSE;
        llOwnerSay("Sensor off...");
        llSensorRemove( );
          
        }
        else
        {
        on = TRUE;
        llOwnerSay("Sensor initialised...");
       llSensorRepeat("","", AGENT,19.0, PI,10.0);
           
  }
   }
    }

 

Link to comment
Share on other sites

You try to iterate over the detected avatars but always use the first one in llDetectedKey:

 

if (llDetectedKey(0)!= user)[...]
else if(llDetectedKey(0)== user)

You need to use the counter variable:

        for(i = 0; i < num_detected; i++)        {            if (llDetectedKey(i)!= user)// If user leave out of rage        {                 llShout(0,"Good bye" + (string)user);// Shout is just for test purpose         }           else         {             llSay(0,"Welcome user"); // In fact this part is for test only . It will not say anything in working mode             }

BTW: The second if condition in the else statement is obsolete - either the object description matches the user key or not. There are no more than 2 alternatives.

Link to comment
Share on other sites

Your sensor event is testing for the wrong thing, or at least gets you an answer with fuzzy logic.  If it detects anyone, then it asks "Is the first person I detected the same one whose key is stored in my Description field?" If you are really looking for that one person, the correct way to do it is to rephrase your search:

llSensorRepeat("",llGetObjectDesc(),AGENT,19.0,PI,10.0);

That way, the sensor event ONLY looks for that one person, ignoring all others.  It becomes

sensor(integer num_detected){   llSay(0, "Welcome, user!");}

 

If you want to give that user a goodbye message when s/he leaves your area, you write

sensor (integer num_detected){    llSay(0,"Welcome, user!");    gWasHere = TRUE; // Where gWasHere is a global variable}no_sensor(){    if (gWasHere)  // That is, if the person was here the last time the sensor fired but is not here now ...    {        llSay(0,"Goodbye, user!");        gWasHere = FALSE;    }}

 Of course, if user is outside of chat range or has teleported away, they'll never hear the goodbye message, so you're better off sending it as an IM.  :smileywink:  The other thing to think about is how to keep the script from annoying your visitor with a Hello message every time the sensor fires and s/he is within range.  That's easy to take care of, now that we have the gWasHere variable .....

sensor (integer num_detected){    if(gWasHere == FALSE) // That is, if the person was NOT here the last time the sensor fired ....    {        llSay(0,"Welcome, user!");        gWasHere = TRUE; // Where gWasHere is a global variable    }}no_sensor(){    if (gWasHere)  // That is, if the person was here the last time the sensor fired but is not here now ...    {        llInstantMessage(llGetObjectDesc(),"Goodbye, user!");        gWasHere = FALSE;    }}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4662 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...