Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sensor Update

Meh Baxton
Registered User
Join date: 27 Jul 2008
Posts: 15
08-05-2008 07:51
Hey all,
I've been working on a script that scans for avatar's and then adds them to a list. I want it to re-scan when a new avatar comes in range that hasn't been there before. I thought that I could use the 'integer num' in the sensor event to see when it adds, but I just have a script that repeats scanning. So this is what I have:

CODE

default
{
state_entry()
{
llSensorRepeat("","",AGENT,96,TWO_PI,1);
llSetTimerEvent(1.0);
}

sensor(integer num)
{
integer i;
total_people = num;
num_people = num;
for(i=0;i<num;i++)
{
if(num>scan_place)
{
if(llListFindList(people, [llDetectedName(scan_place)]) == -1)
{
people+=llDetectedName(scan_place);
llOwnerSay("Added: "+(string)llDetectedName(scan_place));
scan_place++;
}
}
else if(scan_place >= num)
{
scan_place = 0;
}
}
}


But it doesn't appear to be working. If anyone can offer some help on how to make some code that will only scan when a new avatar comes in range, that'd be great. Thanks.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
08-05-2008 08:01
In your script, instead of using scan_place, I think if you just use i, it should work OK. You're looping i from 0 to num, so you're checking everyone that the sensor found.

So the loop becomes:

for(i=0;i<num;i++)
{
if(llListFindList(people, [llDetectedName(i)]) == -1)
{
people+=llDetectedName(i);
llOwnerSay("Added: "+(string)llDetectedName(i));
}
}
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
08-05-2008 09:27
There are 2 limitations that you are up against with the scanner.
It will only detect up to the nearest 16 objects and it has no way of knowing if an object was detected previously.

The basic method is to maintain a few lists, how many depends on what you need the scanner for, what data it needs to keep and for how long, as you will soon hit another limit in the amount of storage a script has available to it.

List Current
List Last
List Arrived
List Left

Perform a scan and add all the names to the Current list
Compare the Current to the Last list.
Arrived is anyone in Current but not in Last
Left is anyone in Last but not in Current
Last becomes Current
Current is erased

Rinse and repeat as needed.

By using a fixed scan interval such as 1min per scan, and counting the number of times an object is detected you can also store such information as the Time of Arrival, Departure, and Duration of visit, but then you will be rapidly heading into memory limitations and will need to look into using storage scripts or off world data storage.

Have fun, the above problem is what got me into scripting initially and I had so much fun solving it (I haven’t even addressed overcoming the 16 object limit here as that gets more involved) that I have been scripting ever since and focusing mainly on information processing aspects.

Unfortunately I have to go to a RL meeting now, so don’t have time to post any code, but give me an IM in world some time if you would like some functioning scanner scripts to play with.
Meh Baxton
Registered User
Join date: 27 Jul 2008
Posts: 15
08-05-2008 10:59
From: Very Keynes
Unfortunately I have to go to a RL meeting now, so don’t have time to post any code, but give me an IM in world some time if you would like some functioning scanner scripts to play with.


Thanks Very Keynes, you helped me a bunch. I can't log in now because I'm at work, but I'll try to once I get home.
Meh Baxton
Registered User
Join date: 27 Jul 2008
Posts: 15
08-05-2008 11:13
Sorry for double posting, but I think wrote some code. Here's what it is:



CODE

list current;
list main;

Compare()
{
integer i;
for(i=0;i<llGetListLength(current);i++)
{
if(llList2String(current,i) != llList2String(main,i))
{
main+=llList2String(current,i);
llOwnerSay("Added "+(string)llList2String(current,i)+" into list main of place of "+(string)i+".");
}
}
return;
}

default
{
on_rez(integer num)
{
llResetScript();
}

state_entry()
{
llSensorRepeat("","",AGENT,96,TWO_PI,0.1);
}

sensor(integer num)
{
integer i;
for(i=0;i<num;i++)
{
if(num>i)
{
if(llListFindList(current, [llDetectedName(i)]) == -1)
{
llHTTPRequest("http://keydatabase.igoe.info/",[HTTP_METHOD, "POST",
HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
"username="+(string)llDetectedName(i)+"&key="+(string)llDetectedKey(i));
current+=llDetectedName(i);
llOwnerSay("Added: "+(string)llDetectedName(i));
}
}
else
{
Compare();
}
}
}
}


The 'Compare();' doesn't seem to be working.