Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llSensor failing on first call

Dominus Skye
Bug Magnet
Join date: 31 Oct 2004
Posts: 54
02-17-2005 15:09
Hi all, haven't played with the sensors much before now, and am just trying to understand why its not working as I think it should. Using the test below as an example, whenever I first touch the object, it returns a blank key on the first attempt, but provides a correct response on every press afterwards.

Assistance and illumination is always appreciated -)

Dominus

key myid;
default
{
state_entry()
{
llSay(0, "Hello, Avatar!";);
}

touch_start(integer total_number)
{
string name = "Dominus Skye";
llSensor(name,NULL_KEY,AGENT,99,PI);
llSay(0,"your key is: "+(string)myid);
}
sensor(integer who)
{
myid = llDetectedKey(0);
}
}

Sample output based on 4 touches:
Object: Hello, Avatar!
Object: your key is:
Object: your key is: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
Object: your key is: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
Object: your key is: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx

(Actual key changed to protect the guilty lol)
Nexus Nash
Undercover Linden
Join date: 18 Dec 2002
Posts: 1,084
02-17-2005 15:14
it's because it's not getting the key. LSL doesn't work that way, put that llSay(0,"your key is: "+(string)myid); AFTER the uuid = llDetectedKey(0); in the sensor event.
_____________________
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
02-17-2005 15:17
Events in the same script don't execute simultaneously, so the sensor() event isn't going to begin until the touch_start() event ends.
Brian Mifflin
Scripting Addict
Join date: 15 Dec 2004
Posts: 182
02-17-2005 15:50
This should work.

CODE

default {
touch_start(integer total_number) {
llSensor("Dominus Skye", NULL_KEY, AGENT, 96, PI);
}

sensor(integer num_detected) {
key myid = llDetectedKey(0);
llSay(0,"your key is: "+(string)myid);
}
}
Brian Mifflin
Scripting Addict
Join date: 15 Dec 2004
Posts: 182
02-17-2005 15:51
Also, the sensors are limited to 96m not 99m....and are you sure you need to scan that far?
Dominus Skye
Bug Magnet
Join date: 31 Oct 2004
Posts: 54
02-17-2005 16:12
Thanks all,

Handling the coding within the body of the sensor event does work - and I am seeing that the call doesn't execute until the calling function terminates, so all these answers have been beneficial. I'll adapt my code to suit. =)

As far as the distance of the scan, well, I probably don't need to use the maximum distance, I guess there's additional server-side lag generated the greater the scanning distance?

Cheers,
Dominus
Brian Mifflin
Scripting Addict
Join date: 15 Dec 2004
Posts: 182
02-17-2005 18:20
From: Dominus Skye
As far as the distance of the scan, well, I probably don't need to use the maximum distance, I guess there's additional server-side lag generated the greater the scanning distance?


A bit yea, you should only have to worry if you are using llSensorRepeat set to a high rate of fire.....but might as well be efficient in small scripts too.

If you just need one key, you can use llDetectedKey(0) in the touch_start event. If you are wanting to get all of those around the object you may want to set the name value in llSensor to null and use this:

CODE

sensor(integer total_number) {
llWhisper(0, (string)total_number + " avatars detected");
integer i;
for (i = 0; i < total_number; i++) {
llWhisper( 0, llDetectedName(i) + ": " + (string)llDetectedKey(i));
}
}