Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Detect Object

Patryk Stirling
Registered User
Join date: 30 Jul 2004
Posts: 26
12-12-2004 08:51
Is it possible for a script to detect another object ???

In the wiki page, it's written in the llDetectedName function description ...

Returns the name of detected object number

And for the DetectedKey function description ....

Returns the key of detected object number

WHAT ARE THESE NUMBERS ????? :confused:
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
12-12-2004 10:14
The Detected functions are used within the detection events, touch, sensor, and collision, and all their variants.

For example, if you have a sensor running, and during one of its sweeps, it detects a group of objects that match its detection criteria. This will cause a sensor() event to be called. The sensor event stores the total number of detected objects in an integer that must be defined in the sensor event itself, ie.

CODE
sensor( integer num_detected )
{
...
}

In this case, num_detected holds the total number of objects detected. Within the sensor event, you can use the Detected functions to gather more information about those detected objects, by referring to them by number. Bear in mind that Detected functions start counting from 0. For example, llDetectedName( 0 ) will return the name of the first object detected (or in the case of a sensor, the object nearest to the sensor).

The following script will detect the nearest 16 avatars within 24m, and display their names above the sensor object:

CODE
default
{
state_entry()
{
// Scan for agents within 24m, in all directions, every 10 seconds
llSensorRepeat( "", NULL_KEY, AGENT, 24, PI, 10 ) ;
}

sensor( integer num_detected )
{
integer i ; // A counter
string displaytext ; // Someplace to hold the results

// There are num_detected agents found, numbered from 0 to num_detected - 1
for( i = 0; i < num_detected; i += 1 )
{
// This will add each name to displaytext in the format of
// "#. Firstname Lastname", one name per line. For neatness,
// it counts from 1, instead of 0.
displaytext += (string)( i + 1 ) + ". " + llDetectedName( i ) + "\n" ;
}

// Displays the list of names over the scripted object
llSetText( displaytext, < 1, 1, 1 >, 1.0 ) ;
}
}


Needless to say, I'm awful at explaining this stuff. Anybody else? :D
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Patryk Stirling
Registered User
Join date: 30 Jul 2004
Posts: 26
12-12-2004 12:50
Thanks .. ! :)

Is there a way, for a sensor, to scan for more then one name in criteria ?

like

llSensor("name1"|"name2"|"name3","",ACTIVE|PASSIVE,20,PI);

or maybe I could use a list ....

list names=["name1","name2","name3"];

llSensor(names,"",ACTIVE|PASSIVE,20,PI);

The fact is that I tried the methods and that don't work...

Anybody got an idea ?
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
12-12-2004 13:22
CODE
list names = ["name1", "name2", "name3"];

scan(){
integer i;
integer count = llListLength( names ) - 1;
for (i = 0 ; i < count ; i++ ){
llSensor( llList2String( names, i ), "", AGENT, 96, PI );
}
}

default{
touch_start ( integer t ){
scan();
}
sensor( integer n ){
llWhisper( 0, llDetectedName( 0 ) + " has been detected." );
}
}

I appologize if there is a syntax error in this... but how it works, everytime you touch the object, it will loop throgh the names in the list - scan the name - if found it will say they've been detected - then go to the next name until the list has been looped through.

--Water
_____________________
From: Philip Linden

For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
Patryk Stirling
Registered User
Join date: 30 Jul 2004
Posts: 26
12-12-2004 13:25
Wooohooo thanks !
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
12-12-2004 13:28
also, as an alternative to lists, you could nest if/then/elses into the sensor event.

CODE
    llSensor( "", "", AGENT,  96, PI );
....
sensor( integer s ){
integer i;
for( i = 0; i < s ; i++ );
if( llDetectedName( i ) == "Name1" ){
...do some code....
}
if( llDetectedName( i ) == "Name2" ){
...do some code....
}
next;
}
}
....

But i think it would be more effective to use the first method i mentioned.

--Water
_____________________
From: Philip Linden

For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
12-12-2004 15:49
if you were going to do if inside the sensor function. Wouldn't it be better to do it like this? I know it is basically the same thing. But this would run just a little faster.

CODE
    llSensor( "", "", AGENT,  96, PI );
....
sensor( integer s ){
integer i;
for( i = 0; i < s ; i++ )
{
string name = llDetectedName( i );

if( name == "Name1" ){
...do some code....
}
else if( name == "Name2" ){
...do some code....
}
}
}
....
Water Rogers
Registered User
Join date: 1 May 2003
Posts: 286
12-12-2004 17:09
Sure, kurt... that would work too. Wasn't really taking performance into consideration with a list of three names.

--Water
_____________________
From: Philip Linden

For the more technically minded - the problem is actually NOT the asset server (or 'asshat' as you prefer to affectionately call it herein).
Over Sleeper
I Dream in LSL
Join date: 12 Jan 2006
Posts: 141
05-07-2006 18:47
From: Water Rogers
CODE
list names = ["name1", "name2", "name3"];

scan(){
integer i;
integer count = llListLength( names ) - 1;
for (i = 0 ; i < count ; i++ ){
llSensor( llList2String( names, i ), "", AGENT, 96, PI );
}
}

default{
touch_start ( integer t ){
scan();
}
sensor( integer n ){
llWhisper( 0, llDetectedName( 0 ) + " has been detected." );
}
}

I appologize if there is a syntax error in this... but how it works, everytime you touch the object, it will loop throgh the names in the list - scan the name - if found it will say they've been detected - then go to the next name until the list has been looped through.

--Water


How about if you want to scan for a particluar set of objects that start with the same letters... such as

Over Sleepers ....

Which would find
Over Sleepers Chair
Over Sleepers Bed
Over Sleeper Snooze button

like that.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
05-07-2006 23:53
For the equivalent of wildcard searching you get much less good results I'm afraid. You have to search for everything (llSensor("", "" ACTIVE | PASSIVE, 96, PI) will get all objects), then cycle through the returned information and match the first however many characters of llDetectedName() to the wildcard you've chosen.

That won't return much - only the closest 16 objects will be sensed this way.

If that doesn't make sense, searching in this forum for llSensor will give you quite a lot of good, and recent examples.
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
05-08-2006 00:17
Oh wow, this is an old thread! Heh... I'm sleepy, it's late, and I'm not thinking straight. But I do rhyme. :D

This scans within 20m on the command '/4scan namegoeshere'. It'll wildcard match, I think.

CODE
string gsScanParam ;

default
{
state_entry()
{
llListen( 4, "", llGetOwner(), "" ) ;
}

listen( integer channel, string name, key id, string message )
{
list holder = llParseString2List( message, [" "], [] ) ;
string command = llList2String( holder, 0 ) ;

if( command == "scan" )
{
gsScanParam = "" ;
integer i ;

for( i = 1; i < llGetListLength( holder ); i ++ )
{
gsScanParam += llList2String( holder, i ) ;
}

gsScanParam = llToLower( gsScanParam ) ;

llSensor( "", NULL_KEY, AGENT | ACTIVE | PASSIVE, 20, PI ) ;
}

}

sensor( integer num )
{
integer i ;
integer j ;
list holder ;
string match ;

for( i = 0; i < num; i++ )
{
holder = llParseString2List( llDetectedName ( i ), [" "], [] ) ;
match = "" ;

for( j = 0; j < llGetListLength( holder ); j++ )
{
match += llList2String( holder, j ) ;
}

match = llToLower( match ) ;

if( llGetSubString( match, 0, llStringLength( gsScanParam ) - 1 ) == gsScanParam )
{
llOwnerSay( llDetectedName( i ) + " detected..." ) ;
}
}
}
}
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"