Difference between revisions of "Template:LSL Constants Sensor"

From Second Life Wiki
Jump to navigation Jump to search
m (added also_articles)
(moved samples into template)
Line 46: Line 46:
{{#if:{{{no_wrapper|}}}||{{!}}} }}
{{#if:{{{no_wrapper|}}}||{{!}}} }}


{{#vardefine:also_articles|{{#var:also_articles}}*http://lslwiki.net/lslwiki/wakka.php?wakka=ObjectType}}
{{#vardefine:also_articles|{{#var:also_articles}}*[http://lslwiki.net/lslwiki/wakka.php?wakka=ObjectType Object Type]}}
 
{{#if:{{{examples|}}}|
{{#vardefine:examples|{{#var:examples}}
Using llDetectedType() in collision event:
<lsl>
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 active 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 == 3)// AGENT & ACTIVE
        {
            llSay(0, "I have been struck by an avatar.");
        }
        else if(type == 10)// SCRIPTED & ACTIVE
        {
            llSay(0, "I have been struck by a phisical object containing any active script.");
        }
        else if(type == 12)// SCRIPTED & PASSIVE
        {
            llSay(0, "This is impossible. Non-physical objects cannot trigger this event.");
        }
    }
}
</lsl>
Using llDetectedType() in sensor event:
<lsl>
default
{
    touch_start(integer numberDetected)
    {
        llSensor("", "", (ACTIVE|PASSIVE|AGENT), 20.0, PI); // activates the sensor.
    }
 
    sensor (integer numberDetected)
    {
        integer i = 0;
        while(i < numberDetected)
        {
            integer type = llDetectedType(i);
            string message;
            message += (string)i + ", " + llDetectedName(i) + ", ";
            list typeList;
            if(AGENT & type)
            {
                typeList += "AGENT";
            }
            if(ACTIVE & type)
            {
                typeList += "ACTIVE";
            }
            if(PASSIVE & type)
            {
                typeList += "PASSIVE";
            }
            if(SCRIPTED & type)
            {
                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.");
    }
}
</lsl>
Using as the filter for llSensor*() functions:
<lsl>
integer done;
 
tellit(integer detected)
{
    integer i = 0;
    while(i < detected)
    {
        integer type = llDetectedType(i);
        string message;
        llWhisper(0, (string)i + ", " + llDetectedName(i));
        i++;
    }
}
default
{
    touch_start(integer detected)
    {
        llWhisper(0, "AGENT");
        llSensor("", "", AGENT, 20.0, PI);
    }
    sensor(integer detected)
    {
        if(done == 0)
        {   
            tellit(detected);
            llWhisper(0, "ACTIVE");
            llSensor("", "", ACTIVE, 20.0, PI);
            ++done;
        }
        else if(done == 1)
        {
            tellit(detected);
            llWhisper(0, "AGENT|ACTIVE");
            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!");
        }
    }
   
    no_sensor()
    {
        llWhisper(0, "None.");
        if(done == 11)
        {
            llSay(0, "Phew!");
        }
        else
        {
            ++done;
        }
    }
}
</lsl>
see [http://lslwiki.net/lslwiki/wakka.php?wakka=ObjectType Object Type] for detail
}}}}
<noinclude>{{#var:examples}}</noinclude>

Revision as of 03:17, 22 May 2010

Flag Mask Description (llDetectedType()) Description (llSensor() and llSensorRepeat() mask)
AGENT 0x1 Agents. Agents.
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)