Difference between revisions of "Template:LSL Constants Sensor"

From Second Life Wiki
Jump to navigation Jump to search
m (Removed dead link to lslwiki)
 
(35 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{#if:{{{no_wrapper|}}}||{{{!}} }}
{{#if:{{{no_wrapper|}}}||{{{!}} }}
{{!}}- valign="top"
{{!}}- valign="top"
{{!}}
{{!}} <div style="display:inline-block;">
{{{!}} {{Prettytable|style={{{tstyle|}}}}}
{{{!}} {{Prettytable|style=margin-bottom:0;{{{tstyle|}}}}}
{{!}}-{{Hl2}}
{{!}}-{{Hl2}}
! colspan="2" {{!}} '''{{{1|}}} Flag Mask'''  
! colspan="2" {{!}} '''{{{1|}}} Flag Mask'''  
! '''Description (llDetectedType())'''
! '''Description ([[llDetectedType]]())'''
! '''Description (llSensor() and llSensorRepeat() mask)'''
! '''Description ([[llSensor]]() and [[llSensorRepeat]]() mask)'''
{{!}}-{{#if:
{{!}} {{#vardefine:AGENT_BY_LEGACY_NAME|{{LSL Const|AGENT_BY_LEGACY_NAME|integer|1|hex=0x1|c=Agents}}}}{{#var:AGENT_BY_LEGACY_NAME}}
{{!}} {{#var:value}}
{{!}} {{#var:comment}}
{{!}} This is used to find agents by {{LSLGC|Avatar/Name|legacy name}}.
{{!}}-
{{!}}-
{{!}} {{#vardefine:AGENT|{{LSL Const|AGENT|integer|1|hex=0x1|c=Agents.}}}}{{#var:AGENT}}
{{!}} {{#vardefine:AGENT|{{LSL Const|AGENT|integer|1|hex=0x1|c=Agents}}}}{{#var:AGENT}}
{{!}} {{#var:value}}
{{!}} {{#var:value}}
{{!}} {{#var:comment}}
{{!}} {{#var:comment}}
{{!}} Agents.
{{!}} This is also used to find agents by {{LSLGC|Avatar/Name|legacy name}}, and is functionally identical to [[AGENT_BY_LEGACY_NAME]]
{{!}}-
{{!}} {{#vardefine:AGENT_BY_USERNAME|{{LSL Const|AGENT_BY_USERNAME|integer|16|hex=0x10|c=Agents}}}}{{#var:AGENT_BY_USERNAME}}
{{!}} {{#var:value}}
{{!}} ''{{HoverText|Reserved|This value is currently not used by llDetectedType}}''
{{!}} This is used to find agents by {{LSLGC|Avatar/Name|username}}.
{{!}}-
{{!}}-
{{!}} {{#vardefine:ACTIVE|{{LSL Const|ACTIVE|integer|2|hex=0x2|c=Physical tasks. (Physical objects & agents) }}}}{{#var:ACTIVE}}
{{!}} {{#vardefine:ACTIVE|{{LSL Const|ACTIVE|integer|2|hex=0x2|c=Physical tasks. (Physical objects & agents) }}}}{{#var:ACTIVE}}
Line 27: Line 37:
{{!}} {{#var:comment}}
{{!}} {{#var:comment}}
{{!}} Objects that has any script, which is doing anything in simulator just now.
{{!}} Objects that has any script, which is doing anything in simulator just now.
{{!}}-
{{!}} {{#vardefine:DAMAGEABLE|{{LSL Const|DAMAGEABLE|integer|32|hex=0x20|c=Objects & agents that are able to process damage.}}}}{{#var:DAMAGEABLE}}
{{!}} {{#var:value}}
{{!}} {{#var:comment}}
{{!}} Filter for objects in world that have a script with [[on_damage]] or a [[final_damage]] event (able to process damage)
{{!}}}
{{!}}}
 
</div><div style="display:inline-block;">
{{{!}} {{Prettytable}}
{{{!}} {{Prettytable}}
{{!}}-{{Hl2}}
{{!}}-{{Hl2}}
!llDetectedType()
![[llDetectedType]]()
!Scripted
!Scripted
!Not Scripted
!Not Scripted
!Agent Standing
!title="Agent sitting on object"|Agent Sitting
{{!}}-
{{!}}-
! Physical
! Physical Movement
{{!}} 10 ({{#var:ACTIVE}}|{{#var:SCRIPTED}})
{{!}} 10 ({{#var:ACTIVE}}|{{#var:SCRIPTED}})
{{!}} 2 ({{#var:ACTIVE}})
{{!}} 2 ({{#var:ACTIVE}})
{{!}} 3 ({{#var:ACTIVE}}|{{#var:AGENT}})
{{!}} 3 ({{#var:ACTIVE}}|{{#var:AGENT}})
{{!}}-
{{!}}-
! Non-Physical
! title="Not moving" | Non-Physical
{{!}} 12 ({{#var:PASSIVE}}|{{#var:SCRIPTED}})
{{!}} 12 ({{#var:PASSIVE}}|{{#var:SCRIPTED}})
{{!}} 4 ({{#var:PASSIVE}})
{{!}} 4 ({{#var:PASSIVE}})
{{!}}}
{{!}} 1 ({{#var:AGENT}})
{{!}} 5 ({{#var:PASSIVE}}|{{#var:AGENT}})
{{!}}}</div>
{{#if:{{{no_wrapper|}}}||{{!}}} }}{{#if:


{{#if:{{{no_wrapper|}}}||{{!}}} }}
{{#if:{{{examples|}}}<noinclude>*</noinclude>|
 
{{#vardefine:also_articles|{{#var:also_articles}}*[http://lslwiki.net/lslwiki/wakka.php?wakka=ObjectType Object Type]}}
 
{{#if:{{{examples|}}}|
{{#vardefine:examples|{{#var:examples}}
{{#vardefine:examples|{{#var:examples}}
Using llDetectedType() in collision event:
'''Using [[llDetectedType]] in [[collision]] event:'''
<lsl>
<source lang="lsl2">
integer type;
integer type;


Line 63: Line 81:
     {
     {
         type = llDetectedType(0);
         type = llDetectedType(0);
         if(type == AGENT)// = 1
         if (type == AGENT)// = 1
         {
         {
             llSay(0, "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(0, "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(0, "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(0, "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 & ACTIVE
         else if (type == (AGENT | ACTIVE) ) // 1 + 2
         {
         {
             llSay(0, "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(0, "I have been struck by a phisical 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(0, "This is impossible. Non-physical objects cannot trigger this event.");
             llSay(0, "This is impossible. Non-physical objects cannot trigger this event.");
Line 93: Line 111:
     }
     }
}
}
</lsl>
</source>
Using llDetectedType() in sensor event:
'''Using [[llDetectedType]] in [[sensor]] event:'''
<lsl>
<source lang="lsl2">
default
default
{
{
     touch_start(integer numberDetected)
     touch_start(integer numberDetected)
     {
     {
         llSensor("", "", (ACTIVE|PASSIVE|AGENT), 20.0, PI); // activates the sensor.
         llSensor("", "", ACTIVE | PASSIVE | AGENT, 20.0, PI); // activates the sensor.
     }
     }


     sensor (integer numberDetected)
     sensor (integer numberDetected)
     {
     {
         integer i = 0;
         integer i;
         while(i < numberDetected)
         while(i < numberDetected)
         {
         {
Line 112: Line 130:
             message += (string)i + ", " + llDetectedName(i) + ", ";
             message += (string)i + ", " + llDetectedName(i) + ", ";
             list typeList;
             list typeList;
             if(AGENT & type)
             if (type & AGENT)
             {
             {
                 typeList += "AGENT";
                 typeList += "AGENT";
             }
             }
             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";
Line 130: Line 148:
             message += llDumpList2String(typeList, "|");
             message += llDumpList2String(typeList, "|");
             llWhisper(0, message);
             llWhisper(0, message);
             i++;
             ++i;
         }
         }
     }
     }
Line 140: Line 158:
     }
     }
}
}
</lsl>
</source>
Using as the filter for llSensor*() functions:
'''Using filter in {{LSLGC|Sensor|llSensor*}} functions:'''
<lsl>
<source lang="lsl2">
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(0, (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(0, "AGENT");
         // Make a Strided list of text and sensor type combinations
        llSensor("", "", AGENT, 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(0, "ACTIVE");
            llSensor("", "", ACTIVE, 20.0, PI);
            ++done;
        }
        else if(done == 1)
         {
         {
            tellit(detected);
             llWhisper(0, (string) (x+1) + ": " + llDetectedName(x) );
            llWhisper(0, "AGENT|ACTIVE");
             ++x;
            llSensor("", "", AGENT|ACTIVE, 20.0, PI);
            ++done;
        }
        else if(done == 2)
        {
            tellit(detected);
            llWhisper(0, "PASSIVE");
            llSensor("", "", PASSIVE, 20.0, PI);
            ++done;
        }
        else if(done == 3)
        {   
            tellit(detected);
            llWhisper(0, "AGENT|PASSIVE");
            llSensor("", "", AGENT|PASSIVE, 20.0, PI);
            ++done;
        }
        else if(done == 4)
        {   
            tellit(detected);
            llWhisper(0, "ACTIVE|PASSIVE");
            llSensor("", "", ACTIVE|PASSIVE, 20.0, PI);
            ++done;
        }
        else if(done == 5)
        {   
            tellit(detected);
            llWhisper(0, "AGENT|ACTIVE|PASSIVE");
            llSensor("", "", AGENT|ACTIVE|PASSIVE, 20.0, PI);
            ++done;
        }
        else if(done == 6)
        {   
            tellit(detected);
             llWhisper(0, "SCRIPTED");
            llSensor("", "", SCRIPTED, 20.0, PI);
            ++done;
        }
        else if(done == 7)
        {   
            tellit(detected);
            llWhisper(0, "AGENT|SCRIPTED");
            llSensor("", "", AGENT|SCRIPTED, 20.0, PI);
            ++done;
        }
        else if(done == 8)
        {   
            tellit(detected);
            llWhisper(0, "ACTIVE|SCRIPTED");
            llSensor("", "", ACTIVE|SCRIPTED, 20.0, PI);
            ++done;
        }
        else if(done == 9)
        {   
            tellit(detected);
            llWhisper(0, "AGENT|ACTIVE|SCRIPTED");
            llSensor("", "", AGENT|ACTIVE|SCRIPTED, 20.0, PI);
            ++done;
        }
        else if(done == 10)
        {   
            tellit(detected);
            llWhisper(0, "PASSIVE|SCRIPTED");
            llSensor("", "", PASSIVE|SCRIPTED, 20.0, PI);
             ++done;
        }
        else if(done == 11)
        {   
            tellit(detected);
            llSay(0, "Phew!");
         }
         }
        SenseNextType();
    }
    no_sensor()
    {
        llWhisper(0, "none");
        SenseNextType();
    }
}
</source>
'''Detecting [[DAMAGEABLE|damageable]] things with sensors:'''
<source lang="lsl">
default
{
    state_entry()
    {
        llSensor("", "", SCRIPTED|AGENT|DAMAGEABLE, 20, PI);
     }
     }
   
 
     no_sensor()
     no_sensor()
     {
     {
         llWhisper(0, "None.");
         llOwnerSay("Nothing detected");
         if(done == 11)
    }
 
    sensor(integer num_detected)
    {
        llOwnerSay("Detected " + (string)num_detected + " damageable thing(s)");
         integer i;
        for (i = 0; i < num_detected; ++i)
         {
         {
             llSay(0, "Phew!");
             string name = llDetectedName(i);
        }
            integer isAgent = llDetectedType(i) & AGENT;
        else
            list types = ["Object", "Agent"];
        {
 
             ++done;
             llOwnerSay(llList2String(types, isAgent) + ": " + name);
         }
         }
     }
     }
}
}
</lsl>
</source>
see [http://lslwiki.net/lslwiki/wakka.php?wakka=ObjectType Object Type] for detail
}}}}
}}}}
<noinclude>{{#var:examples}}</noinclude>
 
}}<noinclude>{{#var:examples}}</noinclude>

Latest revision as of 08:10, 7 November 2024

Flag Mask Description (llDetectedType()) Description (llSensor() and llSensorRepeat() mask)
AGENT_BY_LEGACY_NAME 0x1 Agents This is used to find agents by legacy name.
AGENT 0x1 Agents This is also used to find agents by legacy name, and is functionally identical to AGENT_BY_LEGACY_NAME
AGENT_BY_USERNAME 0x10 Reserved 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.
DAMAGEABLE 0x20 Objects & agents that are able to process damage. Filter for objects in world that have a script with on_damage or a final_damage event (able to process damage)
llDetectedType() Scripted Not Scripted Agent Standing Agent Sitting
Physical Movement 10 (ACTIVE|SCRIPTED) 2 (ACTIVE) 3 (ACTIVE|AGENT) 3 (ACTIVE|AGENT)
Non-Physical 12 (PASSIVE|SCRIPTED) 4 (PASSIVE) 1 (AGENT) 5 (PASSIVE|AGENT)

Using llDetectedType in collision event:

integer type;

default
{
    state_entry()
    {
        llVolumeDetect(TRUE);
    }
    collision_start(integer detected)
    {
        type = llDetectedType(0);
        if (type == AGENT)// = 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 | ACTIVE) ) // 1 + 2
        {
            llSay(0, "I have been struck by an avatar.");
        }
        else if (type == (SCRIPTED | ACTIVE) ) // = 8 + 2
        {
            llSay(0, "I have been struck by a physical object containing any script.");
        }
        else if (type == (SCRIPTED | PASSIVE) ) // = 8 + 4
        {
            llSay(0, "This is impossible. Non-physical objects cannot trigger this event.");
        }
    }
}

Using llDetectedType in sensor event:

default
{
    touch_start(integer numberDetected)
    {
         llSensor("", "", ACTIVE | PASSIVE | AGENT, 20.0, PI); // activates the sensor.
    }

    sensor (integer numberDetected)
    {
        integer i;
        while(i < numberDetected)
        {
            integer type = llDetectedType(i);
            string message;
            message += (string)i + ", " + llDetectedName(i) + ", ";
            list typeList;
            if (type & AGENT)
            {
                typeList += "AGENT";
            }
            if (type & ACTIVE)
            {
                typeList += "ACTIVE";
            }
            if (type & PASSIVE)
            {
                typeList += "PASSIVE";
            }
            if (type & SCRIPTED)
            {
                typeList += "SCRIPTED";
            }
            message += llDumpList2String(typeList, "|");
            llWhisper(0, message);
            ++i;
        }
    }
 
    no_sensor()
    {
        // This is impossible if range = 20.0 and you are standing within 10m!
        llWhisper(0, "Nothing is near me at present."); 
    }
}

Using filter in llSensor* functions:

// Report nearby sensed objects and avatars under sundry categories

list     SenseTypes;
integer  gIndex;

SenseNextType()
{
    string  text = llList2String( SenseTypes, gIndex);
    integer tipe = llList2Integer(SenseTypes, gIndex + 1);
    if (tipe)
    {
        llWhisper(0, text);
        llSensor("", NULL_KEY, tipe, 20.0, PI);
        gIndex += 2;   // increment by stride
    }
    else
        llWhisper(0, "--- Finished ---");
}

default
{
    touch_start(integer detected)
    {
        // Make a Strided list of text and sensor type combinations
        // (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)
    {
        integer x;
        while (x < detected)
        {
            llWhisper(0, (string) (x+1) + ": " + llDetectedName(x) );
            ++x;
        }
        SenseNextType();
    }
    no_sensor()
    {
        llWhisper(0, "none");
        SenseNextType();
    }
}

Detecting damageable things with sensors:

default
{
    state_entry()
    {
        llSensor("", "", SCRIPTED|AGENT|DAMAGEABLE, 20, PI);
    }

    no_sensor()
    {
        llOwnerSay("Nothing detected");
    }

    sensor(integer num_detected)
    {
        llOwnerSay("Detected " + (string)num_detected + " damageable thing(s)");
        integer i;
        for (i = 0; i < num_detected; ++i)
        {
            string name = llDetectedName(i);
            integer isAgent = llDetectedType(i) & AGENT;
            list types = ["Object", "Agent"];

            llOwnerSay(llList2String(types, isAgent) + ": " + name);
        }
    }
}