Difference between revisions of "AGENT"
Jump to navigation
Jump to search
(Thoroughly tested to the best of my abilities.) |
m |
||
(8 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{LSL Constant | {{LSL Constant | ||
|inject-2={{#vardefine:also_constants|{{LSL Constants Sensor|no_wrapper=true|examples=*}}}} | |||
|name=AGENT | |name=AGENT | ||
|type=integer | |type=integer | ||
| | |hvalue=0x1 | ||
|desc | |desc=If it is contained in the result of [[llDetectedType]], it means it is avatar.<br />If it is used as an filter of [[llSensor]] or [[llSensorRepeat]], it will search for avatars by {{LSLGC|Avatar/Name|legacy name}}. Use of this constant in this context is not recommended as {{#var:AGENT_BY_LEGACY_NAME}} is more informative. | ||
|caveats=There is no avatar whose [[llDetectedType]] is ''equal to'' 1([[AGENT]]) since there is no avatar who doesn't require the physical calculation, even if they are just standing. Standing agent's type will be equal to 3([[AGENT]]<nowiki>|</nowiki>[[ACTIVE]]). Sitting agent's type will be equal to 5([[AGENT]]<nowiki>|</nowiki>[[PASSIVE]]). | |||
|functions= | |functions= | ||
{{LSL DefineRow||[[llDetectedType]]|}} | {{LSL DefineRow||[[llDetectedType]]|}} |
Latest revision as of 20:18, 19 October 2013
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Description
Constant: integer AGENT = 0x1;The integer constant AGENT has the value 0x1
If it is contained in the result of llDetectedType, it means it is avatar.
If it is used as an filter of llSensor or llSensorRepeat, it will search for avatars by legacy name. Use of this constant in this context is not recommended as AGENT_BY_LEGACY_NAME is more informative.
Caveats
Related Articles
Constants
|
Functions
• | llDetectedType | |||
• | llSensor | |||
• | llSensorRepeat |
Examples
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);
}
}
}