Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llSensorRepeat isn't working right

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-08-2005 08:20
I'm trying to have a fish counter for my aquarium, but this thing is behaving oddly, not returning accurate counts (will give 1 shark and 14 fish when there are actually 6 sharks and 160 something fish).

CODE


integer shark;
integer fish;


default
{
state_entry()
{
llSensorRepeat("",NULL_KEY,ACTIVE|PASSIVE|SCRIPTED,96,PI,1);
}

sensor(integer total_number)
{
shark = 0;
fish = 0;
integer i;
for ( i = 0; i < total_number; i++ )
{
if (llDetectedName(i) == "Shark")
{
shark = shark + 1;
}
if (llDetectedName(i) == "A-Life Fish")
{
fish = fish + 1 ;
}
}
llSetText("Sharks: " + (string) shark + "\nFish: " + (string) fish,<1,1,1>,1);
}

no_sensor()
{
}
}
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
12-08-2005 08:25
You've only got it scanning on PI radians there... that's not it is it?
Ushuaia Tokugawa
Nobody of Consequence
Join date: 22 Mar 2005
Posts: 268
12-08-2005 08:31
Sensors will only pick up the first 16 objects they see.

Instead of llSensorRepeat, I would suggest two calls to llSensor inside a timer, each one filtering a specific name ("A-Life Fish", and "Shark";). You still won't be able to see all 160 of your fish, but you won't be sensing other objects either.
_____________________
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-08-2005 08:50
From: Ushuaia Tokugawa
Sensors will only pick up the first 16 objects they see.

Instead of llSensorRepeat, I would suggest two calls to llSensor inside a timer, each one filtering a specific name ("A-Life Fish", and "Shark";). You still won't be able to see all 160 of your fish, but you won't be sensing other objects either.


ah, I wasn't aware of the 16 limit. so if I wanted an accurate count of my ecosystem that's well over 150 animals large, is it possible to use a script to get an exact head count, or will I have to manually count the population?
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
12-08-2005 08:57
Build a list of llDetectedKeys. But for something like 160 objects you may run out of memory. There's some clever tricks to get around this, such as using multiple scripts to gain more memory, or compressing the keys, since, after all, they are only strings of text.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-08-2005 10:38
rez up a matrix of closely packed phantom transparent prims that each sense just a portion of the volume, and ignore any objects outside their assigned space. Put them close enough together that they're not going to get more than 16 fish in their range, and report the keys back to the original script through llSay().
AcidRaven Harrington
Linux User
Join date: 18 Jun 2005
Posts: 86
12-08-2005 22:50
Ok I am a bit new on alot of LSL but why not have them all be linked and use Linked Messages? Becuse aren't linked messages better than llsay?
_____________________
Acidraven Harrington
Child Avatar
Height detector 1.0.4: AcidRaven Harrington is 1.191803 m
(3 feet 11 inches) tall. (counting your shoes)

Yo, ho, haul together,
hoist the Colors high…
Heave ho, thieves and beggars,
never say we die.
Freedom is for Everyone.
http://www.gopetition.com/petitions/full-reign-of-self-expression-for-consenting-adults-in-second-life.html
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-09-2005 16:59
From: AcidRaven Harrington
Ok I am a bit new on alot of LSL but why not have them all be linked and use Linked Messages? Becuse aren't linked messages better than llsay?
You're right. I normally build sensor matrixes to cover a large area, and they're too big to link.

But for a small area, you could make a grid of linked sensors.
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-09-2005 23:14
From: Argent Stonecutter
rez up a matrix of closely packed phantom transparent prims that each sense just a portion of the volume, and ignore any objects outside their assigned space. Put them close enough together that they're not going to get more than 16 fish in their range, and report the keys back to the original script through llSay().


the problem is that because most of the fish have a schooling AI, there will generally be between 20-30 in a section of the aquarium. making a general sensor matrix still run into the 16max limit as they swim around
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
12-10-2005 01:13
I'm not sure when listens get throttled in terms of queuing the event triggers - but rather than sensoring you could have the fish etc. llSay() their positions on some suitable channel (and maybe different ones for sharks, fish, food etc.) so they can use their AI that way.

Fishies then don't necessarily need to listen to other fish and so on... It's a different logic, but could work. Otherwise you could do it with sensor's limited by name (so you fire different sensors off a timer event but reasonably rapidly) so they detect their closest fish with one ping and flock, detect sharks with another and flee, detect food with a third and aim that way.
Evan Oud
Registered User
Join date: 18 Apr 2005
Posts: 30
12-10-2005 01:22
You also could just write a script to put in the fish that every so often to say something on a channel ( one besides 0 ) And each fish would say this command, then have a listening script in a prim somewhere that listens for the fish to say something, then when it hears chat from them to add them to a list, make the fish say this command like every few hours and make the listener prim reset after a few hours and listen again. Also if you want it get a exact ammout of fish at any given time you could make add in the listener for it to listen to owner for a command which would reset its counter and shout a command on a hidden channel ( which the fish would listen for ) and that would make then all say the command so the listener would get a new count... Not sure if this would work but just an idea.. You might have problems with all the fish talking at one time.. But not sure, I dont really have a fish farm! lol



Hope this helps!
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
12-10-2005 01:55
As a variant of Evan's idea - have each fish say something only at birth at death - tank updates its list as it hears these.
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
12-10-2005 04:07
From: Ordinal Malaprop
You've only got it scanning on PI radians there... that's not it is it?


Actually, PI radians covers the whole arc. The whole two_pi thing is a bad habit which has stuck, you dont need to do it. :)

-Adam
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-10-2005 15:10
From: Senuka Harbinger
the problem is that because most of the fish have a schooling AI, there will generally be between 20-30 in a section of the aquarium. making a general sensor matrix still run into the 16max limit as they swim around
I think I may have confused you somewhere.

The sensor matrix can be made arbitrarily dense, so you can make it as dense as you want... you can even make the spacing between sensors smaller than the size of a fish. Unless the fish are phantom, you're not going to have an overload problem at that scale.

What you would do is have the "primary" sensors call llSensorRepeat(), and if they get 16 responses THEN they tell the nearby "secondary" sensors (through link messages) to do llSensor(). That way you don't have lots of sensors going off unless you need them.

You could also do it the other way, and make the "sensor" a listener and have the fish llSay() an "I'm here" message periodically.