Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sensor Dialog Menu Help

Ody Naglo
Registered User
Join date: 1 Apr 2008
Posts: 31
02-16-2009 14:55
Script works but its limited to 15 people. I want to make it unlimited without adding more Lines of Code not really sure how. I basicly just Want a menu to pop up when I click my object and display Everyones name within 96 meeters. Then when I click a name it sends there Key via llReagionSay. Anyhelp would be Greatfull =) Anyone who helps can choose any item you want from my XstreetSL store for free(1 Item) =).

For you people that like pastbin:
http://pastebin.com/m35bb2ab6

CODE


//Formatted Sensor Dialog script by Evil Fool
//Modified by blazed Undercity
//Now its got a use, i modified to allow owner to do stuff to the ppl that are in the sensor's range

integer followTarget = TRUE;
float endAlpha =1.0;
float startAlpha = 1.0;
integer effectFlags=0;
integer gOwnerOnly = FALSE;
integer gChann = -29250; //make your OWN unique channel to be sure your not on someone else's.
integer gStride = 9;
list names;
list keys;
integer gPos = 0;
key tReq;
key texture = "3c8ec327-0bc2-a823-891f-b5650e51936e";

dialog(key id)
{
integer nTop = gPos + gStride - 1;
list buttons = llList2List(names, gPos, nTop);
string msg = llDumpList2String(buttons, "\n");
while(llGetListLength(buttons) % 3 != 0)
{ buttons = llListInsertList(buttons , [" "], gStride);
}
if (gPos >= gStride)
{ buttons += ["PREVIOUS"];
}
if (nTop - 1 < llGetListLength(names))
{ buttons += ["NEXT"];
}
llDialog(id, "Targets in Range: \n \n" + msg, ["END","Myself"] + buttons, gChann);
}
default
{
state_entry()
{
llListen(gChann, "", NULL_KEY, "");
}

touch_start(integer num_times)
{ if ( ( gOwnerOnly == TRUE && llDetectedKey(0) == llGetOwner() ) || gOwnerOnly == FALSE)
{tReq = llDetectedKey(0);
llSensor("", NULL_KEY, AGENT, 96.0, PI);

}
}
no_sensor()
{
key id = llGetOwner();
llDialog(id,"To Follow a target, you and the bot must be within 96 meters of your desired target.", ["Myself","NoThanks"], gChann);
}

sensor(integer num_detected)
{
names = [];
gPos = 0;
integer i;

for (i = 0; i < num_detected; i++)
{
names = names + llDetectedName(i);
}

keys = [];
integer k;

for (k = 0; k < num_detected; k++)
{
keys = keys + llDetectedKey(k);
}

dialog(tReq);

}


///This script handles 16 keys & names associated with the dialog buttons. Feel free to add more.




listen(integer channel, string name, key id, string msg)
{
string key0 = llList2String(keys, 0);
string key1 = llList2String(keys, 1);
string key2 = llList2String(keys, 2);
string key3 = llList2String(keys, 3);
string key4 = llList2String(keys, 4);
string key5 = llList2String(keys, 5);
string key6 = llList2String(keys, 6);
string key7 = llList2String(keys, 7);
string key8 = llList2String(keys, 8);
string key9 = llList2String(keys, 9);
string key10 = llList2String(keys, 10);
string key11 = llList2String(keys, 11);
string key12 = llList2String(keys, 12);
string key13 = llList2String(keys, 13);
string key14 = llList2String(keys, 14);
string key15 = llList2String(keys, 15);
string key16 = llList2String(keys, 16);
string name0 = llList2String(names, 0);
string name1 = llList2String(names, 1);
string name2 = llList2String(names, 2);
string name3 = llList2String(names, 3);
string name4 = llList2String(names, 4);
string name5 = llList2String(names, 5);
string name6 = llList2String(names, 6);
string name7 = llList2String(names, 7);
string name8 = llList2String(names, 8);
string name9 = llList2String(names, 9);
string name10 = llList2String(names, 10);
string name11 = llList2String(names, 11);
string name12 = llList2String(names, 12);
string name13 = llList2String(names, 13);
string name14 = llList2String(names, 14);
string name15 = llList2String(names, 15);
string name16 = llList2String(names, 16);
string me = id;
integer b_channel =-9911;

if (msg == "NEXT")
{
gPos = gPos + gStride;
dialog(id);
}
else if (msg == "PREVIOUS")
{
gPos = gPos - gStride;
dialog(id);
}
else if (msg == " ")
{

}



//If you wanna do stuff to the Avatars Detected, you must do the same for all the 'else if' statements below

else if (msg == "END")
{
llSay(0,"test end");
llSay(0,"test end");
llSay(0,"test end");
llSleep(1);
llSay(0,"test end");

}
else if (msg == "Myself")
{
llSay(0,"test " + me);

}


else if (msg == name0)
{
llSay(0,name0 + " " + key0);
}
else if (msg == name1)
{
llSay(0,name1 + " " + key1);
}
else if (msg == name2)
{
llSay(0,name2 + " " + key2);
}
else if (msg == name3)
{
llSay(0,name3 + " " + key3);
}
else if (msg == name4)
{
llSay(0,name4 + " " + key4);
}
else if (msg == name5)
{
llSay(0,name5 + " " + key5);
}
else if (msg == name6)
{
llSay(0,name6 + " " + key6);
}
else if (msg == name7)
{
llSay(0,name7 + " " + key7);
}
else if (msg == name8)
{
llSay(0,name8 + " " + key8);
}
else if (msg == name9)
{
llSay(0,name9 + " " + key9);
}
else if (msg == name10)
{
llSay(0,name10 + " " + key10);
}
else if (msg == name11)
{
llSay(0,name11 + " " + key11);
}
else if (msg == name12)
{
llSay(0,name12 + " " + key12);
}
else if (msg == name13)
{
llSay(0,name13 + " " + key13);
}
else if (msg == name14)
{
llSay(0,name14 + " " + key14);
}
else if (msg == name15)
{
llSay(0,name15 + " " + key15);
}




}
}

/
CODE
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
02-16-2009 15:38
I'm afraid the sensor event can only receive 16 avatars/objects at a time, and there is no way to change that intrinsic limit. If more than 16 are actually detected, then it will give you the ones nearest the sensor.

In other words, the only way to extend it would involve quite a lot more lines of code, and more objects with sensors, communicating across a sim (or one object which flies around, although that would involve even more code!).


EDIT: by the way, that code is rather horrifically inefficient! (No offense.) There is surely no need to extract all the names and keys, one by one, from the lists into separate variables. All you're doing is using up more memory for a theoretical (and negligible) speed improvement... but since it's re-extracting all that data in every listen event, the speed improvement is hugely outweighed.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
02-16-2009 15:39
Two problems. Sensor is limited to 16 returns, to scan more then that you are going to have to narrow the range and rotate the containing prim. Example; scan 180 degrees instead of 360 then rotate the prim 180 degrees and scan again. Every full rotation and you would want to wipe the list and rebuild it again. The other problem is the posted code, it could do with a bit of refactoring. More then half of those lines can be thrown away. Just use one list and enter detected name followed by detected key in strides. Populate the button list by calling up the list in strides of 2 which will pull up just the names. Push the button with a name and use something like this in the listen:

llList2String(namesKeys, llListFindList(message) + 1); which will call up the associated key.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum