Difference between revisions of "Template:LSL Constants Sensor"

From Second Life Wiki
Jump to navigation Jump to search
m (AGENT is deprecated, use AGENT_BY_LEGACY_NAME instead)
(use (SCRIPTED | ACTIVE) etc. instead of numeric value. Replace 3rd example (which aborted wrongly on no-sensor) with more compact code)
Line 72: Line 72:
     {
     {
         type = llDetectedType(0);
         type = llDetectedType(0);
         if(type == AGENT_BY_LEGACY_NAME)// = 1
         if (type == AGENT_BY_LEGACY_NAME)// = 1
         {
         {
             llSay(PUBLIC_CHANNEL, "This is impossible. Since there is no avatar who doesn't require the physical calculation.");
             llSay(0, "This is impossible. Since there is no avatar who doesn't require the physical calculation.");
         }
         }
         else if(type == ACTIVE)// = 2
         else if (type == ACTIVE)// = 2
         {
         {
             llSay(PUBLIC_CHANNEL, "I have been struck by a physical object not containing any script.");
             llSay(0, "I have been struck by a physical object not containing any script.");
         }
         }
         else if(type == PASSIVE)// = 4
         else if (type == PASSIVE)// = 4
         {
         {
             llSay(PUBLIC_CHANNEL, "This is impossible. Non-physical objects cannot trigger this event.");
             llSay(0, "This is impossible. Non-physical objects cannot trigger this event.");
         }
         }
         else if(type == SCRIPTED)// = 8
         else if (type == SCRIPTED)// = 8
         {
         {
             llSay(PUBLIC_CHANNEL, "This is impossible. Since there is no object which isn't physical nor non-physical.");
             llSay(0, "This is impossible. Since there is no object which isn't physical nor non-physical.");
         }
         }
         else if(type == 3)// AGENT_BY_LEGACY_NAME & ACTIVE
         else if (type == (AGENT_BY_LEGACY_NAME | ACTIVE) ) // 1 + 2
         {
         {
             llSay(PUBLIC_CHANNEL, "I have been struck by an avatar.");
             llSay(0, "I have been struck by an avatar.");
         }
         }
         else if(type == 10)// SCRIPTED & ACTIVE
         else if (type == (SCRIPTED | ACTIVE) ) // = 8 + 2
         {
         {
             llSay(PUBLIC_CHANNEL, "I have been struck by a physical object containing any script.");
             llSay(0, "I have been struck by a physical object containing any script.");
         }
         }
         else if(type == 12)// SCRIPTED & PASSIVE
         else if (type == (SCRIPTED | PASSIVE) ) // = 8 + 4
         {
         {
             llSay(PUBLIC_CHANNEL, "This is impossible. Non-physical objects cannot trigger this event.");
             llSay(0, "This is impossible. Non-physical objects cannot trigger this event.");
         }
         }
     }
     }
Line 114: Line 114:
     sensor (integer numberDetected)
     sensor (integer numberDetected)
     {
     {
         integer i = 0;
         integer i;
         while(i < numberDetected)
         while(i < numberDetected)
         {
         {
Line 121: Line 121:
             message += (string)i + ", " + llDetectedName(i) + ", ";
             message += (string)i + ", " + llDetectedName(i) + ", ";
             list typeList;
             list typeList;
             if(AGENT_BY_LEGACY_NAME & type)
             if (type & AGENT_BY_LEGACY_NAME)
             {
             {
                 typeList += "AGENT_BY_LEGACY_NAME";
                 typeList += "AGENT_BY_LEGACY_NAME";
             }
             }
             if(ACTIVE & type)
             if (type & ACTIVE)
             {
             {
                 typeList += "ACTIVE";
                 typeList += "ACTIVE";
             }
             }
             if(PASSIVE & type)
             if (type & PASSIVE)
             {
             {
                 typeList += "PASSIVE";
                 typeList += "PASSIVE";
             }
             }
             if(SCRIPTED & type)
             if (type & SCRIPTED)
             {
             {
                 typeList += "SCRIPTED";
                 typeList += "SCRIPTED";
             }
             }
             message += llDumpList2String(typeList, "|");
             message += llDumpList2String(typeList, "|");
             llWhisper(PUBLIC_CHANNEL, message);
             llWhisper(0, message);
             ++i;
             ++i;
         }
         }
Line 146: Line 146:
     {
     {
         // This is impossible if range = 20.0 and you are standing within 10m!
         // This is impossible if range = 20.0 and you are standing within 10m!
         llWhisper(PUBLIC_CHANNEL, "Nothing is near me at present.");  
         llWhisper(0, "Nothing is near me at present.");  
     }
     }
}
}
Line 152: Line 152:
'''Using filter in {{LSLGC|Sensor|llSensor*}} functions:'''
'''Using filter in {{LSLGC|Sensor|llSensor*}} functions:'''
<lsl>
<lsl>
integer done;
// Report nearby sensed objects and avatars under sundry categories


tellit(integer detected)
list    SenseTypes;
integer  gIndex;
 
SenseNextType()
{
{
     integer i = 0;
    string  text = llList2String( SenseTypes, gIndex);
     while(i < detected)
     integer tipe = llList2Integer(SenseTypes, gIndex + 1);
     if (tipe)
     {
     {
         integer type = llDetectedType(i);
         llWhisper(0, text);
         string message;
         llSensor("", NULL_KEY, tipe, 20.0, PI);
        llWhisper(PUBLIC_CHANNEL, (string)i + ", " + llDetectedName(i));
         gIndex += 2;   // increment by stride
         ++i;
     }
     }
    else
        llWhisper(0, "--- Finished ---");
}
}
default
default
{
{
     touch_start(integer detected)
     touch_start(integer detected)
     {
     {
         llWhisper(PUBLIC_CHANNEL, "AGENT_BY_LEGACY_NAME");
         // Make a Strided list of text and sensor type combinations
        llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME, 20.0, PI);
        // (Can't use '|' in Global, unfortunately)
        SenseTypes = [
            "AGENT_BY_LEGACY_NAME", AGENT_BY_LEGACY_NAME,
            "ACTIVE", ACTIVE,
            "AGENT_BY_LEGACY_NAME|ACTIVE", AGENT_BY_LEGACY_NAME|ACTIVE,
            "PASSIVE", PASSIVE,
            "AGENT_BY_LEGACY_NAME|PASSIVE", AGENT_BY_LEGACY_NAME|PASSIVE,
            "ACTIVE|PASSIVE", ACTIVE|PASSIVE,
            "AGENT_BY_LEGACY_NAME|ACTIVE|PASSIVE", AGENT_BY_LEGACY_NAME|ACTIVE|PASSIVE,
            "SCRIPTED", SCRIPTED,
            "AGENT|SCRIPTED", AGENT|SCRIPTED,
            "ACTIVE|SCRIPTED", ACTIVE|SCRIPTED,
            "AGENT_BY_LEGACY_NAME|ACTIVE|SCRIPTED", AGENT_BY_LEGACY_NAME|ACTIVE|SCRIPTED,
            "PASSIVE|SCRIPTED", PASSIVE|SCRIPTED,
            "", 0 ];
        gIndex = 0;
        SenseNextType();       // Kick off the sensing sequence
     }
     }
     sensor(integer detected)
     sensor(integer detected)
     {
     {
         if(done == 0)
         integer x;
         {   
         while (x < detected)
            tellit(detected);
            llWhisper(PUBLIC_CHANNEL, "ACTIVE");
            llSensor("", NULL_KEY, ACTIVE, 20.0, PI);
            ++done;
        }
        else if(done == 1)
         {
         {
            tellit(detected);
             llWhisper(0, (string) (x+1) + ": " + llDetectedName(x) );
             llWhisper(PUBLIC_CHANNEL, "AGENT_BY_LEGACY_NAME|ACTIVE");
             ++x;
            llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME | ACTIVE, 20.0, PI);
            ++done;
        }
        else if(done == 2)
        {
            tellit(detected);
            llWhisper(PUBLIC_CHANNEL, "PASSIVE");
            llSensor("", NULL_KEY, PASSIVE, 20.0, PI);
            ++done;
        }
        else if(done == 3)
        {   
            tellit(detected);
            llWhisper(PUBLIC_CHANNEL, "AGENT_BY_LEGACY_NAME|PASSIVE");
            llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME | PASSIVE, 20.0, PI);
            ++done;
        }
        else if(done == 4)
        {   
            tellit(detected);
            llWhisper(PUBLIC_CHANNEL, "ACTIVE|PASSIVE");
            llSensor("", NULL_KEY, ACTIVE | PASSIVE, 20.0, PI);
            ++done;
        }
        else if(done == 5)
        {   
            tellit(detected);
            llWhisper(PUBLIC_CHANNEL, "AGENT_BY_LEGACY_NAME|ACTIVE|PASSIVE");
            llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME | ACTIVE | PASSIVE, 20.0, PI);
             ++done;
        }
        else if(done == 6)
        {   
            tellit(detected);
            llWhisper(PUBLIC_CHANNEL, "SCRIPTED");
            llSensor("", NULL_KEY, SCRIPTED, 20.0, PI);
            ++done;
        }
        else if(done == 7)
        {   
            tellit(detected);
            llWhisper(PUBLIC_CHANNEL, "AGENT|SCRIPTED");
            llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME | SCRIPTED, 20.0, PI);
            ++done;
        }
        else if(done == 8)
        {   
            tellit(detected);
            llWhisper(PUBLIC_CHANNEL, "ACTIVE|SCRIPTED");
            llSensor("", NULL_KEY, ACTIVE | SCRIPTED, 20.0, PI);
            ++done;
        }
        else if(done == 9)
        {   
            tellit(detected);
            llWhisper(PUBLIC_CHANNEL, "AGENT_BY_LEGACY_NAME|ACTIVE|SCRIPTED");
            llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME | ACTIVE | SCRIPTED, 20.0, PI);
            ++done;
        }
        else if(done == 10)
        {   
            tellit(detected);
            llWhisper(PUBLIC_CHANNEL, "PASSIVE|SCRIPTED");
            llSensor("", NULL_KEY, PASSIVE | SCRIPTED, 20.0, PI);
            ++done;
        }
        else if(done == 11)
        {   
            tellit(detected);
            llSay(PUBLIC_CHANNEL, "Phew!");
         }
         }
        SenseNextType();
     }
     }
   
     no_sensor()
     no_sensor()
     {
     {
         llWhisper(PUBLIC_CHANNEL, "None.");
         llWhisper(0, "none");
         if(done == 11)
         SenseNextType();
        {
            llSay(PUBLIC_CHANNEL, "Phew!");
        }
        else
        {
            ++done;
        }
     }
     }
}
}

Revision as of 02:40, 9 January 2013

Flag Mask Description (llDetectedType()) Description (llSensor() and llSensorRepeat() mask)
AGENT 0x1 Agents DEPRECATED: Use AGENT_BY_LEGACY_NAME
AGENT_BY_LEGACY_NAME 0x1 Agents This is used to find agents by legacy name.
AGENT_BY_USERNAME 0x10 Agents This is used to find agents by username.
ACTIVE 0x2 Physical tasks. (Physical objects & agents) Physical objects that are moving or objects containing an active script. Thus, it is using SL server resources now.
PASSIVE 0x4 Non-physical objects. Non-scripted or script is inactive and non-physical or, if physical, not moving. Thus, it is not using SL server resources now.
SCRIPTED 0x8 Objects containing any active script. Objects that has any script, which is doing anything in simulator just now.
llDetectedType() Scripted Not Scripted
Physical 10 (ACTIVE|SCRIPTED) 2 (ACTIVE)
Non-Physical 12 (PASSIVE|SCRIPTED) 4 (PASSIVE)

Using llDetectedType in collision event:

<lsl> integer type;

default {

   state_entry()
   {
       llVolumeDetect(TRUE);
   }
   collision_start(integer detected)
   {
       type = llDetectedType(0);
       if (type == AGENT_BY_LEGACY_NAME)// = 1
       {
           llSay(0, "This is impossible. Since there is no avatar who doesn't require the physical calculation.");
       }
       else if (type == ACTIVE)// = 2
       {
           llSay(0, "I have been struck by a physical object not containing any script.");
       }
       else if (type == PASSIVE)// = 4
       {
           llSay(0, "This is impossible. Non-physical objects cannot trigger this event.");
       }
       else if (type == SCRIPTED)// = 8
       {
           llSay(0, "This is impossible. Since there is no object which isn't physical nor non-physical.");
       }
       else if (type == (AGENT_BY_LEGACY_NAME