Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sensor ,

LIO Diesel
Registered User
Join date: 2 Sep 2008
Posts: 28
12-05-2008 01:39
HI


can some one help- me to achieve this.
sensor(integer num)
{
if(detected an avator which is detected previously)
{ do this; }
else
{do this;}
}
or in words,
for the given sensor call " llSensorRepeate("","",AGENT,2,PI,1);"
i dont want to execute my code again if sensor detected same avator, when sensor triggers.

ay ideas.....


LIO
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
12-05-2008 01:47
What you'll need to do is create a list of avatar keys, and every time you detect an avatar, use "llListFindList" to determine if you've detected that avatar before or not. If you have *not* detected it before, then add it to the list, and execute your code.

For example, declare this globally (at the top of your script):

CODE

list detectedAvatars = [];


Then in your sensor event:

CODE

integer i = 0;
key av = NULL_KEY;
for (i = 0; i < num_detected; i++) {

av = llDetectedKey(i);
if (llListFindList(detectedAvatars, [av]) < 0) {
// Avatar has NOT been detected before
detectedAvatars += [av];
// Add more code here
} else {
// Avatar has been detected before
}

}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
Simple visitor detector/greeter
12-05-2008 03:12
This tiny program may prove useful:
CODE

// Visitor detector to the bone
// will register avs and report them if they are new to the register
// will remove avs from register when they have not been sensed for some time
// free for anybody to read, copy, compile, use, rip apart, tramble on and flush
// by Dora Gustafson, Studio Dora 2008

float sd_Range = 10.0; // The range of the sensor in meters
float sd_Arc = PI; // The ½ arc of the sensor
float sd_Rate = 2.0; // The repeat rate of the sensor in seconds
integer Life = 30; // Registration will be deleted if not renewed before this number of shots
integer x;
integer i;
integer j;

list Key_register = []; // for detected keys
list Hit_register = []; // number of times each Key was not detected

count_out()
{
for (i = llGetListLength( Hit_register ) - 1 ; i >= 0; i-- )
{
j = llList2Integer( Hit_register, i ) + 1 ;
if (j > Life)
{
Hit_register = llDeleteSubList( Hit_register, i, i );
Key_register = llDeleteSubList( Key_register, i, i );
}
else Hit_register = llListReplaceList(Hit_register, [ j ], i , i );
}
}

default
{
state_entry()
{
llSensorRepeat("", NULL_KEY, AGENT, sd_Range, sd_Arc, sd_Rate);
}

sensor(integer num_detected)
{
for(x = 0 ; x < num_detected ; x++)
{
//if (llGetOwner() != llDetectedKey(x))
{
integer position = llListFindList( Key_register, [llDetectedKey(x)]);
if (position >= 0) Hit_register = llListReplaceList( Hit_register, [ 0 ], position , position );
else
{
Key_register += [ llDetectedKey(x) ];
Hit_register += [ 0 ];
//llSay( PUBLIC_CHANNEL, " welcome " + llDetectedName(x) );
//llInstantMessage(llGetOwner(),llDetectedName(x) + " has entered" );
llOwnerSay(llDetectedName(x) + " is here" );
}
}
}
count_out();
}

no_sensor()
{
count_out();
}
}

You may comment in and out parts of it to adjust to your needs.
Happy sensing:)
_____________________
From Studio Dora
LIO Diesel
Registered User
Join date: 2 Sep 2008
Posts: 28
12-05-2008 03:27
thanks pedro ..It solve my problem.
LIO Diesel
Registered User
Join date: 2 Sep 2008
Posts: 28
12-05-2008 04:28
Dora thanks to you also ......