Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Keeping the owner on the "Do not shoot" list? =x

woofbag Fudo
Registered User
Join date: 3 Aug 2006
Posts: 31
12-22-2007 02:19
Hello, my friend and I are building an auto turret (It's anti-abuse, if you're wondering...) and one of its features is having a list of people you can let control your turrets by saying "Listen <name here>", another feature it's SUPPOSED to have is the ability to take people OFF the list by saying "Remove <name here>" (This also removes the user from the other lists: Do not shoot list and Attack list), but when you say "Remove", regardless of the name you say, everyone on every list is removed! I can't figure it out, and my scripting buddies are all on vacation, can anyone help?? Here's where I think the problem is:

(Dots represent parts of script I didn't include in the post)
...else if(first == "remove";)
{
list aname = llParseString2List(llToLower(llKey2Name(llGetOwner())),[" "],[]);
if(llList2String(newfind,1) != llList2String(aname,0)){
donotshoot = llDeleteSubList(donotshoot,llListFindList(donotshoot,[llList2String(newfind,1)]),llListFindList(donotshoot,[llList2String(newfind,1)]));
attack = llDeleteSubList(attack,llListFindList(attack,[llList2String(newfind,1)]),llListFindList(attack,[llList2String(newfind,1)]));
listento = llDeleteSubList(listento,llListFindList(listento,[llList2String(newfind,1)]),llListFindList(listento,[llList2String(newfind,1)]));}
}
else...
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
12-23-2007 03:06
Firstly, I reformated your code to try and make it look a little less intimidating! :p

...else if(first == "remove";)
{
list aname = llParseString2List(llToLower(llKey2Name(llGetOwner ())), [" "], []);

if(llList2String(newfind, 1) != llList2String(aname, 0))
{

donotshoot = llDeleteSubList(donotshoot,
llListFindList(donotshoot, [llList2String(newfind, 1)]),
llListFindList(donotshoot, [llList2String(newfind, 1)]));

attack = llDeleteSubList(attack,
llListFindList(attack, [llList2String(newfind, 1)]),
llListFindList(attack, [llList2String(newfind, 1)]));

listento = llDeleteSubList(listento,
llListFindList(listento, [llList2String(newfind, 1)]),
llListFindList(listento, [llList2String(newfind, 1)]));
}

}

The easiest way to delete an entire list is by doing llDeleteSubList(list, 0, -1).
Whereas, the instance llDeleteSubList(list, -1, -1) just deletes the last entry.

So, I'm at a loss. As llListFindList(list, [llList2String(newfind, 1)]) should always return the same result the llDeleteSubList should always be directed to remove a single index (even if that index is -1).

If I'd have made a suggestion (without knowing the problem :p) it would be to check that (newfind, 1) is really in the list or else you risk unconditionally deleting the last entry.

Are you sure it's not some code we're not being shown that's doing the deed?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-23-2007 05:39
it's vaguely possible (untested) that it's trying to return a inverted listing as in the case of feeding it a bigger start number then end number for deleting....

before feeding the name to llDeleteSubList, instead see if it first exsists in the list

integer vIntIndex;
if (~(index = llListFindList( donotshoot, llList2List( newfind, 1 ) ))){
donotshot = llDeleteSubList( donotshoot, index, index );
}
if (~(index = llListFindList( attack, llList2List( newfind, 1 ) ))){
attack= llDeleteSubList( attack, index, index );
}
if (~(index = llListFindList( listento, llList2List( newfind, 1 ) ))){
listento= llDeleteSubList( listento, index, index );
}

even better if they can only be in one list, use else if, to keep from testing lists they can't be in
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
woofbag Fudo
Registered User
Join date: 3 Aug 2006
Posts: 31
12-23-2007 20:56
giving each list its own remove command seemed to work, don't really know why, but I'm not questioning it due to fear of jinxing it =x
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-23-2007 21:21
From: woofbag Fudo
giving each list its own remove command seemed to work, don't really know why, but I'm not questioning it due to fear of jinxing it =x

voodoo progaming will get you...

if you don't know why it works, or not, it's always better to find out... it'll save you debugging headaches down the road when things don't do what you expect, plus the next time you use something similar you'll know what does and doesn't work, and will know how to get around it (or sometimes use it to your advantage)

I'm guessing it was doing as I mentioned above, and clearing any list that it didn't find an index in (ie -1).... filtering them to be sure the name is actually in the list first (as in my example) should cure that... assuming there isn't some other code that was manipulating those lists and causing the problem...

the above example may seem complicated so I'll break it down a bit
llListFindList() will return a number from -1 (not found) to listLength -1 (the last index)
storing it in a variable (index) means you get a number from -1 to n
~index changes any value of -1 to 0 (false) but any other number will be true (not 0) thus controlling your if statement to be true for any number except -1
since we stored the index, we can reuse it in the deleteSubList to get a valid index and don't have to keep calling listfindList... makes it a little faster and uses less code
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -