Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

problem with showing the correct distance to detected av

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
11-19-2005 08:04
here's the script. it "works" but the distance is off by an extra about 170m. any ideas why?

the target's key is announced in a channel by another attachment, which this script then lisens for and begins listing the distance to the target in a llSetText which is updated 4 times a second.

CODE

list gpos = [];

default
{
state_entry()
{
llListen(982, "scan v1.5", NULL_KEY, ""); //listens on channel 982 for a key from theradar
}

listen(integer channel, string name, key id, string message)
{
if (message == "")
{
llSetText("No Target",<0,1,0>,1); //if a blank key is sent, say no target
llSensorRemove(); //stops the repeating sensor
}
else
{
key tarkey = (key) message;// get the target's key from the radar's sensor
llSensorRepeat("",tarkey,AGENT,96,PI,.25);//calls the sensor 4 times a second for "real-time" distance
}

}

sensor(integer total_number)
{
integer i;
for ( i = 0; i < total_number; i++ )
{

list gpos = gpos + [llDetectedPos(i)]; //I had to declare a list for some reason for it to compile. dunno why.
}
vector tarpos = llDetectedPos(i); //target's position
vector mypos =llGetPos(); //my position
float tardist = llVecDist(tarpos,mypos); //distance between both positions
llSetText("Distance to target: \n" + (string) tardist, <1,1,1>,1); //sets the distance to target text
list gpos = []; //clears the list to stop memory overflow of the script
}

no_sensor()
{
llSetText("Target out of range",<1,0,0>,1); //if there is nothing sensed, then the person who's key was sent has moved out of range.
}

}


[edit] on further testing it appears that I'm not retrieving the data from the sensor correctly. any tips?
Tezkat Murakami
Ebil Genius
Join date: 25 Sep 2005
Posts: 12
11-19-2005 08:21
You're sensing for a unique key. Unless something is seriously borked, total_number should never be greater than 1, so you can skip the whole list thing and just detect for item 0. With the loop there, it looks like you're incrementing i to 1 past the range of objects detected, so llDetectedPos(i) returns garbage.
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
11-19-2005 08:26
Since you're scanning by key, you can only get one return, so there's no need to sort through the llDetected* info:

CODE
default
{
state_entry()
{
llListen(982, "scan v1.5", NULL_KEY, ""); //listens on channel 982 for a key from theradar
}

listen(integer channel, string name, key id, string message)
{
if (message == "")
{
llSetText("No Target", <0.0,1.0,0.0>, 1.0); //if a blank key is sent, say no target
llSensorRemove(); //stops the repeating sensor
}
else
{
key tarkey = (key)message;// get the target's key from the radar's sensor
llSensorRepeat("", tarkey, AGENT, 96, PI, 0.25);//calls the sensor 4 times a second for "real-time" distance
}

}

sensor(integer total_number)
{
vector tarpos = llDetectedPos(0); //target's position (We're scanning by key, there will be only one return if it's found)
vector mypos = llGetPos(); //my position
float tardist = llVecDist(tarpos, mypos); //distance between both positions
llSetText("Distance to target:\n" + (string)tardist, <1.0,1.0,1.0>, 1.0); //sets the distance to target text
}

no_sensor()
{
llSetText("Target out of range", <1.0,0.0,0.0>, 1.0); //if there is nothing sensed, then the person who's key was sent has moved out of range.
}
}
_____________________
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
11-19-2005 09:28
works great, but for some reason it's not switching keys when a new one is announced on the channel.
Kala Bijoux
Material Squirrel
Join date: 16 Nov 2004
Posts: 112
11-19-2005 13:05
Maybe try an llSensorRemove before the llSensor - maybe it doesn't update the old sensor, so you need to shut it down and start up a new one for the new key? That's a wild guess, I haven't played with sensors like this.