Difference between revisions of "Template:LSL Constants Sensor"
Jump to navigation
Jump to search
Kireji Haiku (talk | contribs) m (AGENT is deprecated, use AGENT_BY_LEGACY_NAME instead) |
Omei Qunhua (talk | contribs) (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( | 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( | 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( | llSay(0, "This is impossible. Non-physical objects cannot trigger this event."); | ||
} | } | ||
else if(type == SCRIPTED)// = 8 | else if (type == SCRIPTED)// = 8 | ||
{ | { | ||
llSay( | llSay(0, "This is impossible. Since there is no object which isn't physical nor non-physical."); | ||
} | } | ||
else if(type == | else if (type == (AGENT_BY_LEGACY_NAME | ACTIVE) ) // 1 + 2 | ||
{ | { | ||
llSay( | llSay(0, "I have been struck by an avatar."); | ||
} | } | ||
else if(type == | else if (type == (SCRIPTED | ACTIVE) ) // = 8 + 2 | ||
{ | { | ||
llSay( | llSay(0, "I have been struck by a physical object containing any script."); | ||
} | } | ||
else if(type == | else if (type == (SCRIPTED | PASSIVE) ) // = 8 + 4 | ||
{ | { | ||
llSay( | llSay(0, "This is impossible. Non-physical objects cannot trigger this event."); | ||
} | } | ||
} | } | ||
Line 114: | Line 114: | ||
sensor (integer numberDetected) | sensor (integer numberDetected) | ||
{ | { | ||
integer i | 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 | if (type & AGENT_BY_LEGACY_NAME) | ||
{ | { | ||
typeList += "AGENT_BY_LEGACY_NAME"; | typeList += "AGENT_BY_LEGACY_NAME"; | ||
} | } | ||
if(ACTIVE | if (type & ACTIVE) | ||
{ | { | ||
typeList += "ACTIVE"; | typeList += "ACTIVE"; | ||
} | } | ||
if(PASSIVE | if (type & PASSIVE) | ||
{ | { | ||
typeList += "PASSIVE"; | typeList += "PASSIVE"; | ||
} | } | ||
if(SCRIPTED | if (type & SCRIPTED) | ||
{ | { | ||
typeList += "SCRIPTED"; | typeList += "SCRIPTED"; | ||
} | } | ||
message += llDumpList2String(typeList, "|"); | message += llDumpList2String(typeList, "|"); | ||
llWhisper( | 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( | 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> | ||
// Report nearby sensed objects and avatars under sundry categories | |||
list SenseTypes; | |||
integer gIndex; | |||
SenseNextType() | |||
{ | { | ||
integer | 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 | default | ||
{ | { | ||
touch_start(integer detected) | 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) | sensor(integer detected) | ||
{ | { | ||
integer x; | |||
while (x < detected) | |||
{ | { | ||
llWhisper(0, (string) (x+1) + ": " + llDetectedName(x) ); | |||
llWhisper( | ++x; | ||
++ | |||
} | } | ||
SenseNextType(); | |||
} | } | ||
no_sensor() | no_sensor() | ||
{ | { | ||
llWhisper( | llWhisper(0, "none"); | ||
SenseNextType(); | |||
} | } | ||
} | } |
Revision as of 02:40, 9 January 2013
|
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