Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Are all objects sensed including avatars?

Vertigo Miles
Registered User
Join date: 31 Mar 2007
Posts: 12
04-02-2007 20:19
Hi, I wanna detect any objects and avatars within a certain range. I made a test script that displayed the object/avatar's detected type (AGENT,ACTIVE,PASSIVE, SCRIPTED) when it is within its range. I used llSensorRepeat to sense objects and avatars in the entry state and displayed the detected types in string form in the sensor event. Of course, I placed this in an object and wear it. But it seems that the detection is inconsistent based on my observed behaviors:

1. Some objects are not detected especially objects w/o scripts and not in motion.
2. I haven't encountered an AGENT object.
3. I can't detect an avatar. (What's an avatars detected type?)
4. I can only detect PASSIVE and active.


I would greatly appreciate if someone can help me with this. Thanks!!!

Here is my script:

default
{
state_entry()
{
llOwnerSay("object started...";);
//start sensing
llSensorRepeat( "", NULL_KEY, AGENT | ACTIVE | PASSIVE
| SCRIPTED, 5.0, PI/2, 0.5);

}

sensor(integer num_detected)
{
integer status = FALSE;
integer i = 0;

// dont display anything if there are no detected objects
for(;(i<num_detected - 1) && (num_detected > 0);i++)
{
// display number of detected objects
llOwnerSay("number of detected objects: " + (string)num_detected);
// display detected name
llOwnerSay(llDetectedName(i));

if(llDetectedType(i) & AGENT)
{
llOwnerSay("Agent detected within 5m range";);
status = TRUE;
}
if(llDetectedType(i) & ACTIVE)
{
llOwnerSay("Active detected within 5m range";);
status = TRUE;
}
if(llDetectedType(i) & PASSIVE)
{
llOwnerSay("Passive detected within 5m range";);
status = TRUE;
}
if(llDetectedType(i) & SCRIPTED)
{
llOwnerSay("Scripted detected within 5m range";);
status = TRUE;
}
}

if(status == FALSE)
{
llOwnerSay("unknown object detected within 5m range";);
}
}

no_sensor()
{
llOwnerSay("no objects within 5m range...";);
}


touch_start(integer total_number)
{
llOwnerSay("working...";);
}
}
_____________________
"We have artists with no scientific knowledge and scientists with no
artistic knowledge and both with no spiritual sense of gravity at all,
and the result is not just bad, it is ghastly"
(Time for real reunification of art and technology is really long
overdue)
- R. Pirsig
AnnMarie Coronet
Registered User
Join date: 20 Nov 2006
Posts: 39
04-02-2007 20:56
Just an initial glance at the script (you might want to use [ php] and [ /php] (without the space) for presenting code in the forum - that way you get better formatting and syntax highlighting).

From: someone

// dont display anything if there are no detected objects
for(;(i<num_detected - 1) && (num_detected > 0);i++)
{


Here you are doing two unnecessary things (as far as I can see at 4.50am). Firstly, since we are in the sensor event at this point, you have no need to check that num_detected isn't 0. Thats what the no_sensor event is for. Secondly, you are missing out on one of the detections - the llDetected index range runs from 0 -> num_detected-1, but by checking that (i < num_detected-1), you are actually stopping the loop one step too early. You would either need to check (i <= num_detected-1) or:-

CODE

// loop through all the detections
for( ; i < num_detected; i++)
{
.....
}


Also, according to the following page in the old Wiki, results get counter-intuitive if you include the SCRIPTED flag. Amongst other things, apparently AGENT | SCRIPTED doesn't detect avatars.

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSensor

Not in world, and the coffee hasn't started to work yet, so I'll add to this if I spot anything else.
Vertigo Miles
Registered User
Join date: 31 Mar 2007
Posts: 12
Are all objects sensed including avatars?
04-02-2007 21:53
Oops thats what I get in copy pasting, I got the num_detected-1(total_number-1) from the wiki but I forgot to set the starting index to 1, sorry for that. I tried your suggestions and I have finally detected an avatar(by removing SCRIPTED). But I can't still detect some objects like walls, towers, plants, anything that is not scripted and not in motion. I believe its not because I removed the SCRIPTED type, because even with it I still can't detect those objects. Am I using llSensorRepeat correctly especially the masks? From what I have assumed, to sense a certain object using llSensorRepeat a mask(detected type) of that object should be specified in the parameters that is why Im placing it all to detect all objects including avatars. Thanks for the help...I need your replies :)
_____________________
"We have artists with no scientific knowledge and scientists with no
artistic knowledge and both with no spiritual sense of gravity at all,
and the result is not just bad, it is ghastly"
(Time for real reunification of art and technology is really long
overdue)
- R. Pirsig
AnnMarie Coronet
Registered User
Join date: 20 Nov 2006
Posts: 39
04-02-2007 22:04
Just to clarify one detail, the detection indices for any of the llDetected* functions is zero-based, so the range is 0 -> (num_detected-1) inclusive.

So if you weren't initialising the loop variable early, your loop would be:-

CODE

integer i;

for(i = 0; i < num_detected; i++)
{
...
}


It's been a little while since i last played around with the llSensor flags, but if I have time I'll run some tests in-world. One reference I found in the quoted Wiki page, sensors won't detect a linked object's child prims, so if the walls you are trying to detect are child prims of a larger linkset, I'm not sure what the sensor would make of them.

Also, I notice you are hammering llDetectedType(i) for every bitwise comparison. You would be better off grabbing the return value into a local variable:-

CODE

sensor(integer num_detected)
{
integer type;
integer i;

for(i = 0 i < num_detected; i++)
{
type = llDetectedType(i);

if(type & AGENT)
{
...
}

...
}
}
Vertigo Miles
Registered User
Join date: 31 Mar 2007
Posts: 12
Are all objects sensed including avatars? Reply to Thread
04-02-2007 22:20
I see...I hope you can add some suggestions on how to detect those unscripted objects that i mentioned below and also if its possible you can check if my llSensorRepeat usage is correct. Thanks :)
_____________________
"We have artists with no scientific knowledge and scientists with no
artistic knowledge and both with no spiritual sense of gravity at all,
and the result is not just bad, it is ghastly"
(Time for real reunification of art and technology is really long
overdue)
- R. Pirsig
AnnMarie Coronet
Registered User
Join date: 20 Nov 2006
Posts: 39
04-02-2007 23:06
Ok, I just tested your script - I tidied it up a bit, and added a touch start/stop for easier reading and testing.

CODE

integer gScanning = FALSE;

default
{
state_entry()
{
llOwnerSay("Scanner initialised...");
}

touch_start(integer count)
{
if(gScanning)
{
// turn off scanner
llSensorRemove();
llOwnerSay("Scanning cancelled");
gScanning = FALSE;
}
else
{
llSensorRepeat("", NULL_KEY, AGENT | ACTIVE | PASSIVE, 5.0, PI/2, 5);
llOwnerSay("Sensor scanning...");
gScanning = TRUE;
}
}

sensor(integer num_detected)
{
// This report wants to be outside the loop, so it only reports once per scan
llOwnerSay("Total detected: " + (string)num_detected);

integer i;
integer type;
integer status;
string report;

for(i = 0; i < num_detected; i++)
{
status = FALSE;
type = llDetectedType(i);
report = "";

if(type & AGENT)
{
report += " AGENT";
status = TRUE;
}

if(type & ACTIVE)
{
report += " ACTIVE";
status = TRUE;
}

if(type & PASSIVE)
{
report += " PASSIVE";
status = TRUE;
}

if(type & SCRIPTED)
{
report += " SCRIPTED";
status = TRUE;
}

if(status == FALSE)
{
report = " UNDEFINED";
}

llOwnerSay(llDetectedName(i) + " is" + report);
}
}

no_sensor()
{
llOwnerSay("None detected...");
}
}


I also toned down the scan frequency to every 5 seconds to stop it spamming the llOwnerSay (0.5sec is a lot of scanning).

From initial tests, it does seem to be locating stationary non-scripted objects as PASSIVE... but as covered in the Wiki, its not detecting objects if they are child prims of a larger linkset (though it'll detect the root prim of the linkset if in range - or maybe its detectng the geometric centre of the linked object, i haven't tested that)

Also interesting to note, llDetectedType is flagging SCRIPTED if the object contains scripts, so although we haven't specifically told the sensor to look for SCRIPTED, llDetectedType is returning all known type information.
Vertigo Miles
Registered User
Join date: 31 Mar 2007
Posts: 12
Are all objects sensed including avatars? Reply to Thread
04-03-2007 00:09
I got your notes and thank you this is a very big help for me... :)
_____________________
"We have artists with no scientific knowledge and scientists with no
artistic knowledge and both with no spiritual sense of gravity at all,
and the result is not just bad, it is ghastly"
(Time for real reunification of art and technology is really long
overdue)
- R. Pirsig