Infinate Loop Problem
|
|
Klaire Larnia
Learner, be gentle....
Join date: 2 Jun 2008
Posts: 41
|
05-23-2009 22:54
Hi, I have a problem. For the last week I have been trying to make my own door system - which I have done (YAY!!!) but I have a problem on the security side of it. I am using a notecard for an AllowList on the door controller. It checks the AV name and if it matches an entry it lets you in. simple enough. My first revision looked in the list each time the controller was activated. But this meant I had reset the script each time which is not a great solution. So I looked at using Lists to get round it. I load the AllowList into a list and then scan that using a "For..." loop. More efficent I thought (please bear in mind until today I have never tried to use either Lists or For loops).... But when I do this, I appear to have an infinate loop problem which causes the door opening command to be called constantly after the first click, which means I have made a mistake somewhere. Below is the code I have for a click verson of the controller. The codecard (which I call AllowList) is a simple list of AV names on seperate lines. Can anyone tell me what I have done wrong as my mind cannot see it. Thanks, Klaire integer Ent = 0; integer iNotecardIndex; integer CardLine = 0; integer AllowLength; integer ListPos; key CardDataRead; string sNotecardName; string CardName; string AvName; string AllowValue; list AllowList = [];
default { state_entry() { CardName = llGetInventoryName(INVENTORY_NOTECARD, 0); CardDataRead = llGetNotecardLine(CardName, CardLine); } dataserver (key Data_id, string CardData) { if (Data_id == CardDataRead) { llSay (0, "1"); if (CardData !=EOF) { llSay (0, "2"); llSay (0, CardData); AllowList = AllowList + CardData; ++CardLine; CardDataRead = llGetNotecardLine(CardName, CardLine);
} } } touch_start(integer total_number) { AvName = llKey2Name(llDetectedKey(0)); AllowLength = llGetListLength(AllowList); for (ListPos = 0; AllowLength; AllowLength++) { AllowValue = llList2String (AllowList, ListPos); if (AllowValue == AvName) { llSay(0, "Doors Opening..."); llSay(-3456, (string)llDetectedKey(0)); } } }
}
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
05-23-2009 23:26
From: Klaire Larnia for (ListPos = 0; AllowLength; AllowLength++)
[/php] i think that needs to be for(ListPos = 0; ListPos < AllowLength;ListPos++) //start list pos at 0, as long as the list pos is less than the length of the list, do your thing and continue to the next list pos but instead of a for loop, you could use llListFindList if(llListFindList(AllowList, [AvName]) != -1)
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
05-23-2009 23:33
touch_start(integer total_number) { AvName = llDetectedName(0); if (llListFindList(AllowList,[AvName]) != -1){ llSay(0, "Doors Opening..."); llSay(-3456, (string)llDetectedKey(0)); } }
|
|
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
|
05-23-2009 23:33
In the touch event it would be easier to do From: someone
touch_start(integer total_number) { if ( ~llListFindList(AllowValue, [llDetectedName(0)])) { open door or whatever } }
llDetectedName is the name of the toucher so there's no need to use llKey2Name. Using llListFindList you can check if the name is in the allowed list. It returns false, or 0, if the name is not in the list.
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
05-23-2009 23:37
or what ron said, they both work the same way, his is probably faster, but that should be AllowList, not AllowValue. and actually, if it's not in the list it returns -1, 0 would be the first index of the list
|
|
Klaire Larnia
Learner, be gentle....
Join date: 2 Jun 2008
Posts: 41
|
05-24-2009 05:16
Thank you for the help. it looks I was trying to use a sledgehammer to crack a hazelnut so to speak then.... Right idea, just not going about it in the right or most appropiate way Klaire
|
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
05-24-2009 05:56
From: Ruthven Willenov actually, if it's not in the list it returns -1, 0 would be the first index of the list Ron's code is correct with respect to this, despite his incorrect comment. To me, that shows why we should avoid use of "~" in examples using llListFindList().
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-24-2009 08:36
From: Lear Cale Ron's code is correct with respect to this, despite his incorrect comment. To me, that shows why we should avoid use of "~" in examples using llListFindList(). misplaced reference: "it"... his comment was referring to the overall test (~llListFindList does return false on not found) but didn't clearly specify the whole test, rather than just the function (which was assumed you'd know the difference)... so the reference defaulted to the nearest descriptive sentence. (which referenced just the function call) english is such a goofy language sometimes. Footnote: while I'm not sure it matters in MONO, in LSO it's faster/smaller to cast single item lists rather than declare them... so (list)x is measurably faster/smaller than [x] in LSO. only applies to single items though. PS no way in hell will you find me writing X != -1 instead of ~X although I do try to comment that in the code for the people here.
_____________________
| | . "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... | - 
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
05-24-2009 08:52
We should write examples however we normally write our own code, commenting when necessary to help people understand what we did. This allows the users to learn more then one way to do something and expands their knowledge base. This is one thing that has changed from when I was first learning. It was common back then to receive multiple, complete, example scripts to demonstrate a point. Seeing how everyone solved the same problem as opposed to a handful of snippets greatly accelerates the learning process.
_____________________
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
|
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
05-24-2009 14:26
From: Void Singer misplaced reference: "it" hmm, I didn't mean to sound like I was correcting you, since what you said was 100% correct and right on point.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-24-2009 16:13
I think you misunderstood, I was refereing to ron's comment with that From: someone It returns false, or 0, if the name is not in the list. it (this situation), exemplifies a failure of english, not a failure of scripting or commenting.
_____________________
| | . "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... | - 
|
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
05-25-2009 04:39
From: Jesse Barnett We should write examples however we normally write our own code, commenting when necessary to help people understand what we did. This allows the users to learn more then one way to do something and expands their knowledge base. As someone who finds this forum incredibly helpful in her attempts to learn scripting, I heartily concur. It's really useful to me to see different ways of doing the same thing. If they are better ways of doing something than the way I'd already been shown or thought of, then the advantage is obvious. But when they are just different approaches to the same problem, it's still so useful to understand them, partly because it helps me understand how LSL works and partly because it helps me to make sense of other examples I'm studying.
|