Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

radar HUD help?

Shelter Deerhunter
Registered User
Join date: 23 May 2008
Posts: 3
05-24-2008 07:10
OK, I have two prims attached as a HUD. One is a button and one is a small thing that the test results of the radar scan hover over.

When the button is clicked, it brings up a blue dialog box with four options: Reset, Rescan, Scanner On and Scanner Off.

The first three work beautifully, they do their functions and when the button is clicked again, the dialog box reappears.

However, when Scanner Off is selected, it indeed turns the scan off but bang, that's it. Clicking on the button no longer works. Resetting scripts from the Tools menu is required to get back to square 1.

I suspect the problem is in script 2 in the radar prim but I also suspect it could use a pair of fresh eyes looking at it.

So, what am I missing here?

IN THE BUTTON:

default
{

touch_start(integer total_number)
{
llSay(123, "radaron";);

}
}


SCRIPT 1 IN THE RADAR PRIM:

list handles;
list time;
list chans;
string users;
list answer;
list button;
list prim;
list mask;
list intchan;

integer ticks;

remove(integer a)
{
llListenRemove(llList2Integer(handles,a));
handles = llDeleteSubList(handles,a,a);
time = llDeleteSubList(time, a,a);
chans = llDeleteSubList(chans, a,a);
answer = llDeleteSubList(answer, a,a);
button = llDeleteSubList(button, a,a);
prim = llDeleteSubList(prim, a,a);
mask = llDeleteSubList(mask, a,a);
intchan = llDeleteSubList(intchan,a,a);
users = llDeleteSubString(users,a*=36,a+35);
}

list TightListParse(string a) {
string b = llGetSubString(a,0,0);
return llParseStringKeepNulls(llDeleteSubString(a,0,0), [a=b],[]);
}

clear()
{
integer a = llGetListLength(handles);
while(a)
{
llListenRemove(llList2Integer(handles,--a));
if(llList2Integer(mask,a)&0x20000)
llMessageLinked(llList2Integer(prim,a), llList2Integer(intchan,a),
llList2String(answer,a), "|-2||"+llGetSubString(users,a * 36,(a * 36) + 35)+"||-1";);
}
llSetTimerEvent(ticks = 0);
}

default
{
state_entry()
{
llOwnerSay("Dialog Module, Version 9.2, Released Under the GNU Lesser General Public License";); llOwnerSay("Copyright (C) 2004-2006, Strife Onizuka, http://www.lslwiki.com/lslwiki/wakka.php?wakka=LibraryDialogModule";);
}

on_rez(integer a)
{
clear();
}

link_message(integer a, integer b, string c, key d)
{
if(b == 12)
{
b = llSubStringIndex(llDeleteSubString(c,0,0), llGetSubString(c,0,0));
list e = TightListParse(d);
integer buttonmask = (integer)llList2String(e,3);
string user = llList2String(e,0);
list buttons = llDeleteSubList(e,0,3);
float timeout = (float)llList2String(e,2);
integer cat = (integer)llFrand(-2147483392.0) - 255;
integer chan = (integer)llDeleteSubString(c, b + 1, 0);
string ans = llDeleteSubString(c,0,b);

if(buttonmask & 0x100000)
clear();
else if(buttonmask & 0x200000)
{
while(1 + (b = llSubStringIndex(users, user)))
{
if(llList2Integer(mask,b/=36)&0x20000)
llMessageLinked(llList2Integer(prim,b), llList2Integer(intchan,b),
llList2String(answer,b), "|-2||"+llGetSubString(users,b * 36,(b * 36) + 35)+"||-1";);
remove(b);
}
if(time == [])
llSetTimerEvent(ticks = 0);
}

if(user == "" || user == NULL_KEY)
user = llGetOwner();
if(!llGetAgentInfo(user))
{
if(buttonmask & 0x40000)
llMessageLinked(a, chan, ans, "|-3||"+user+"||0";);
jump end1;
}
while(1+llListFindList(chans,[cat]))
--cat;

b = llListen(cat,"",user,"";);
llDialog(user, llList2String(e,1), buttons, cat);
if(chan != 12)
{
if(buttons == [])
buttons = ["OK"];
if(buttonmask & ((1<<llGetListLength(buttons)) - 1))
{
chans += cat;
handles += b;
if(timeout < 5.0 || timeout > 7200)
timeout = 5.0;
time += (ticks + (timeout / 5.0));
users += user;
answer += ans;
button += (llGetSubString(d,0,0) + llDumpList2String(buttons, llGetSubString(d,0,0)));
prim += a;
mask += buttonmask;
intchan += chan;
llSetTimerEvent(5.0);
jump end2;
}
}
llListenRemove(b);
if(buttonmask & 0x80000)
llMessageLinked(a, chan, ans, "|-4||"+(string)user+"||0";);
}
@end1;
@end2;
}

listen(integer a, string b, key c, string d)
{
if(a+1 && llGetSubString(users, 36 * a=llListFindList(chans,[a]),(a * 36) + 35) == c)
{
integer f = llListFindList(TightListParse(llList2String(button,a)),[d]);
if(f+1)
{
if(llList2Integer(mask,a)&;(1<<f))
{
list ret = [f, d, c, b,(llList2Float(time,a) - ticks) * 5.0];
if(llSubStringIndex(d = (string)ret,b = "|";) + 1)
{
f = -37;
b = "|\\/?!@#$%^&*()_=:;~{}[]<>`',\n\" qQxXzZ";
do;while(1+llSubStringIndex(d,llGetSubString(b,f,f)) && ++f);
b = llGetSubString(b,f,f);
}
d = "";
llMessageLinked(llList2Integer(prim,a), llList2Integer(intchan,a),
llList2String(answer,a), (b + llDumpList2String(ret, b)));
}
remove(a);
if(time == [])
llSetTimerEvent(ticks = 0);
}
}
}

timer()
{
++ticks;
integer a = llGetListLength(time);
float c;
key d;
while(a)
{
if(((c = llList2Float(time, a)) <= ticks) || !llGetAgentInfo(d = llGetSubString(users,--a * 36,(a * 36) + 35)))
{
if(llList2Integer(mask, a) & 0x10000)
llMessageLinked(llList2Integer(prim,a), llList2Integer(intchan,a),
llList2String(answer,a), "|-1||"+(string)d+"||"+(string)((ticks - c) * 5.0));

remove(a);
}
}
if(time == [])
llSetTimerEvent(ticks = 0);
}
}


SCRIPT 2 IN THE RADAR PRIM:


string status = "none";
list people;
integer maxScanDistance = 96;
vector colour = <1.0, 1.0, 1.0>;
integer maxPeople = 9;
integer scanType = AGENT;
integer scanFreq = 5;
integer scanDistance = 10;


string sepchar = "|";
integer answer = 546;
integer DialogComm = 12;
list MENU_MAIN = ["Reset", "Turn On", "Turn Off", "Re-scan"];
integer num_detected;
key Null = NULL_KEY;

scannerRescan(integer num_detected)
{

llSensorRemove();
llListenRemove(DialogComm);
llSetText("Rescanning...", <1.0, 0.0, 0.0>, 1);
scannerOn(num_detected);
}

scannerReset(integer num_detected)
{
llSetText("Resetting... please be patient", <1.0, 0.0, 0.0>, 1);
llSleep(1);
llSensorRemove();
llSetTimerEvent(0);
llListenRemove(DialogComm);
scannerOn(num_detected);
}

scannerSwitchOn()
{
llSetText("Switching on... please be patient", <1.0, 0.0, 0.0>, 1);
llSleep(1);
}

scannerOn(integer num_detected)
{
llSensorRepeat("", "", scanType, scanDistance, PI, scanFreq);
llSetTimerEvent(15);
people = [];
string result;
integer n = -1;
integer distance = 0;
integer detDist;
string name;

vector pos = llGetPos();

for(n = 0; n < num_detected && n < maxPeople; ++n)
{
vector detPos = llDetectedPos(n);
detDist = (integer)llVecDist(pos, detPos);
float angle = getAngle(llGetPos(), detPos);
name = llKey2Name(llDetectedKey(n));
if(detDist < 96)
{
people += detDist;
people += name;
people += angle;
}
}


people = llListSort(people, 3, TRUE);

num_detected = llGetListLength(people) / 3;
for(n = 0; n < num_detected; ++n)
{
detDist = llList2Integer(people, n * 3);
name = llList2String(people, n * 3 + 1);
float dir = llList2Float(people, n*3+2);
if(detDist > 20 && distance <= 20)
{
result += "<-Chat Range Limit (20m)->\n";
}
result += name;
if(detDist < 20)
{
integer cnt = count(name);
result += " ["+time(cnt)+"]";
}
result += " [" + (string)detDist + "m]";

if(dir < 0 || dir > 360)
{
llOwnerSay("Error:" + (string)dir + ":" + name);
}

if(dir <= 22.5)
{
result += " N\n";
}
else
{
if(dir > 22.5 && dir <= 67.5)
{
result+=" NE\n";
}
else
{
if(dir > 67.5 && dir <= 112.5)
{
result+=" E\n";
}
else
{
if(dir > 112.5 && dir <= 157.5)
{
result+=" SE\n";
}
else
{
if(dir > 157.5 && dir <= 202.5)
{
result+=" S\n";
}
else
{
if(dir > 202.5 && dir <= 247.5)
{
result+=" SW\n";
}
else
{
if(dir > 247.5 && dir <= 292.5)
{
result+=" W\n";
}
else
{
if(dir > 292.5 && dir <= 337.5)
{
result+=" NW\n";
}
else
{
if(dir > 337.5 && dir < 360)
{
result+=" N\n";
}
}
}}}}}}}
distance = detDist;
}


if(num_detected >= maxPeople)
{
scanDistance = distance + 10;
llSensorRepeat("", "", scanType, scanDistance, PI, scanFreq);
}
else
{
if(scanDistance < maxScanDistance)
{
scanDistance += 10;
llSensorRepeat("", "", scanType, scanDistance, PI, scanFreq);
}
}

result += "\nStatus: "
+ status
+ " | freq: "
+ (string)scanFreq
+ " | dist: "
+ (string)scanDistance
+ " | max dist: "
+ (string)maxScanDistance;

if(llStringLength(result) > 254)
{
maxPeople--;
llOwnerSay("Length is " + (string)llStringLength(result) +
" Decrementing max People to "+(string)maxPeople);
}
else
{
if(llStringLength(result) < 200 && num_detected > maxPeople)
{
maxPeople++;
llOwnerSay("Length is " + (string)llStringLength(result) +
" Incrementing max People to " + (string)maxPeople);
}
}
llSetText(result, colour, 1);
}



integer count(string name)
{
integer i = llListFindList(people, [name]);
if(i == -1)
{
people += [name, 0];
return 0;
}
else
{
integer count = llList2Integer(people, i + 1);
people = llListReplaceList(people, [count + scanFreq], i + 1, i + 1);
return count;
}
}


string time(integer cnt)
{
if(cnt > 3600)
{
return (string)(cnt / 3600) + "hr " + (string)((cnt % 3600) / 60) + "min";
}
else
{
if(cnt > 60)
{
return (string)(cnt / 60) + "min";
}
else
{
return (string)cnt + "s";
}
}
}


float getAngle(vector me, vector target)
{
float hyp = llVecDist(me, target);
float yDiff = target.y - me.y;
float xDiff = target.x - me.x;
float angle = llSin(yDiff / hyp);
if(xDiff > 0 && yDiff > 0)
{
return angle * RAD_TO_DEG;
}
if(xDiff > 0 && yDiff < 0)
{
return 90 - angle * RAD_TO_DEG;
}
if(xDiff < 0 && yDiff > 0)
{
return angle * RAD_TO_DEG + 270;
}
if(xDiff < 0 && yDiff < 0)
{
return angle * RAD_TO_DEG + 270;
}
return angle * RAD_TO_DEG;
}

dialog(key user, string message, float timeout, list buttons
, integer buttonmask, integer retchan, list ret)
{
llMessageLinked(llGetLinkNumber(), DialogComm, dump([retchan] + ret, sepchar),
dump([user, message, timeout, buttonmask] + buttons, sepchar));
}

string dump(list a, string b)
{
string c = (string)a;
if(1 + llSubStringIndex(c, b) || llStringLength(b) != 1)
{
b += "|\\/?!@#$%^&*()_=:;~{}[],\n qQxXzZ";
integer d = -llStringLength(b);
while(1 + llSubStringIndex(c, llGetSubString(b,d,d)) && d)
d++;
b = llGetSubString(b,d,d);
}
return b + llDumpList2String(a, b);
}

list parse(string a)
{
string b = llGetSubString(a, 0, 0);
return llParseStringKeepNulls(llDeleteSubString(a, 0, 0), , []);
}



default
{
state_entry()
{
integer rint = 6;
string question = "RADAR AV Scanner.\nWhat would you like to do?";
list Answers = MENU_MAIN;
integer AnswerMask = 0x005;
list ExtraPassback = ["Doing..."];

scannerSwitchOn();
scannerOn(num_detected);
}

on_rez(integer reset)
{
llResetScript();
scannerSwitchOn();
scannerOn(num_detected);
}

sensor(integer num_detected)
{

scannerOn(num_detected);
}

changed(integer change)
{
if(change & 128)
{
llResetScript();
}
}

state_entry()

{
llListen(123,"",NULL_KEY,"";);

}
listen(integer channel, string name, key id, string message)
{
if (message == "radaron";)
{
dialog(llDetectedKey(0)
, "RADAR AV Scanner.\nWhat would you like to do?"
, 30
, MENU_MAIN
, 0xf0fff, answer
, [""]);
llMessageLinked(LINK_ALL_CHILDREN, 0, "START", Null);
}
}

no_sensor()
{
llSetText("Status: " + status
+ " | freq: "
+ (string)scanFreq
+ " | dist: "
+ (string)scanDistance
+ " | max dist: "
+ (string)maxScanDistance, colour, 1);
maxScanDistance += 10;
llSensorRepeat("", "", scanType, maxScanDistance, PI, scanFreq);
}

timer()
{
float fps = llGetRegionFPS();
float timeDilation = llGetRegionTimeDilation();

if(fps < 35 || timeDilation < 0.9) {
maxScanDistance = 32;
if(scanDistance > maxScanDistance) {
scanDistance = maxScanDistance;
}
scanFreq = 240;
status = "poor";
llSetTimerEvent(240);
colour = <1.0, 0.0, 0.0>;
}
else
{

if(fps < 40 || timeDilation < 0.95)
{
maxScanDistance = 64;
if(scanDistance > maxScanDistance)
{
scanDistance = maxScanDistance;
}
scanFreq = 30;
status = "ok";
llSetTimerEvent(120);
colour = <1.0, 1.0, 0.0>;
}
else

{
maxScanDistance = 96;
if(scanDistance > maxScanDistance)
{
scanDistance = maxScanDistance;
}
scanFreq = 1;
llSetTimerEvent(60);
status = "good";
colour = <1.0, 1.0, 1.0>;
}
}
llSensorRepeat("", "", scanType, scanDistance, PI, scanFreq);
}

link_message(integer a, integer b, string c, key d)
{

string val = llList2String(parse(d), 0);



if (val == "3";)
{
llOwnerSay("Re-scanning...";);
scannerRescan(num_detected);
llOwnerSay("Done.";);
}
else if (val == "2";)
{
state scannerOff;
llOwnerSay("Scanning has been turned off.";);
llResetScript();

scannerOn(num_detected);
}
else if (val == "1";)
{
scannerSwitchOn();
scannerOn(num_detected);
llOwnerSay("Scanning has been turned on.";);
}
else if (val == "0";)
{
llOwnerSay("Resetting scanner...";);
scannerReset(num_detected);
llOwnerSay("Done resetting.";);
}

}


attach(key id)
{
if (id == Null)
return;

vector scale = llGetScale();
integer point = llGetAttached();
if ((point == 31) || (point == 35))
{
llSetPos(<0.0,0.0,0.0>;);
}
else
if (point == 32)
{
llSetPos(<0.0, scale.y, -scale.z>;);
}
else
if (point == 33)
{
llSetPos(<0.0, 0.0, -scale.z>;);
}
else
if (point == 34)
{
llSetPos(<0.0, -scale.y, -scale.z>;);
}
else
if (point == 36)
{
llSetPos(<0.0, -scale.y, scale.z>;);
}
else
if (point == 37)
{
llSetPos(<0.0, 0.0, scale.z>;);
}
else
if (point == 38)
{
llSetPos(<0.0, scale.y, scale.z>;);
}
}
}

state scannerOff
{
state_entry()
{
llSensorRemove();
llSetTimerEvent(0);
llListenRemove(DialogComm);
llSetText("Turning off.", <1.0, 0.0, 0.0>, 1);
llSleep(1);
llSetText("", <0.0, 0.0, 0.0>, 0);

}

sensor(integer num_detected)
{
}
no_sensor()
{
llListen(123,"",NULL_KEY,"";);

}
listen(integer channel, string name, key id, string message)
{
if (message == "radaron";)

dialog(llDetectedKey(0)
, "RADAR AV Scanner.\nWhat would you like to do?"
, 30
, MENU_MAIN
, 0xf0fff, answer
, [""]);
llMessageLinked(LINK_ALL_CHILDREN, 0, "START", Null);
llResetScript();
scannerOn(num_detected);
}

link_message(integer a, integer b, string c, key d)
{

string val = llList2String(parse(d), 0);



if (val == "3";)
{
llOwnerSay("Re-scanning...";);
scannerRescan(num_detected);
llOwnerSay("Done.";);
}
else if (val == "2";)
{
scannerReset(num_detected);
llOwnerSay("Scanning has been turned off.";);

}
else if (val == "1";)
{
state default;
scannerSwitchOn();
scannerOn(num_detected);
llOwnerSay("Scanning has been turned on.";);
}
else if (val == "0";)
{
llOwnerSay("Resetting scanner...";);
scannerReset(num_detected);
llOwnerSay("Done resetting.";);
}

}
}
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
05-24-2008 09:31
This is a lot of script to wade around in :p but I think state ScannerOff is deaf. It has an llListen hanging around in no_sensor but there's no llSensor or llSensorRepeat to trigger it? Maybe try the llListen in ScannerOff's state_entry?
Beezle Warburton
=o.O=
Join date: 10 Nov 2006
Posts: 1,169
05-24-2008 09:46
I'd suspect:

sensor(integer num_detected)
{
}
no_sensor()
{
llListen(123,"",NULL_KEY,"";);

}

under state scannerOff.

It only starts the listen if there's no-one around?

And why a sensor in the off state at all?
_____________________
Though this be madness, yet there is method in't.
-- William Shakespeare

Warburton's Whimsies:
In SL
Apez.biz
Shelter Deerhunter
Registered User
Join date: 23 May 2008
Posts: 3
05-24-2008 14:08
That was it indeed, thank you guys.
Shelter Deerhunter
Registered User
Join date: 23 May 2008
Posts: 3
05-24-2008 14:19
From: Beezle Warburton

And why a sensor in the off state at all?




I thought perhaps if it continued to scan in the off state, it might speed things up when turned back on. Sadly, either the premise was wrong or I haven't done it right.
Beezle Warburton
=o.O=
Join date: 10 Nov 2006
Posts: 1,169
05-24-2008 14:36
From: Shelter Deerhunter
I thought perhaps if it continued to scan in the off state, it might speed things up when turned back on. Sadly, either the premise was wrong or I haven't done it right.


Well on of the advantages of turning it off would be the complete lack of sensor lag.

And it won't speed anything up. :)
_____________________
Though this be madness, yet there is method in't.
-- William Shakespeare

Warburton's Whimsies:
In SL
Apez.biz