Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Incorrect Test Condition in an if statement....

Timmins Hamilton
Registered User
Join date: 15 May 2004
Posts: 68
07-16-2004 09:40
Ok, I have a script that I am converting to something more. Its a simple door script and I have added locking to it, but I want members of a list to be able to open it even if its locked. I have the list and want to test is a agent is in the list and if they are then allow the door to open etc etc....

Here is the code.....

---------------------------------------------------------------------
touch_start(integer total_number) {
if (doorsLocked == TRUE)
{

if ( llListFindList( OverrideList, llCSV2List( llDetectedName(0) ) == TRUE)
{
llWhisper(0,llDetectedName(0) + " is using a key to open the door.";);
door(DOOR_OPEN);
state is_open;
} else {
llWhisper(0,llDetectedName(0) + " is knocking on the door.";);
}

} else {
door(DOOR_OPEN);
state is_open;
}
}
---------------------------------------------------------------------

Now I dont know if the test condition will work, but I cant seem to find out. I get told there is a syntax error on the first open curly braces. I can only think that there must be something dreadfully wrong with the test condition.

I am still new at scripting and hope someone can point me in the right direction.

Thanks

Timmins Hamilton
Jack Digeridoo
machinimaniac
Join date: 29 Jul 2003
Posts: 1,170
Re: Incorrect Test Condition in an if statement....
07-16-2004 09:42
Try replacing this line :

if ( llListFindList( OverrideList, llCSV2List( llDetectedName(0) ) == TRUE)

with this :

if ( llListFindList( OverrideList, (list)llDetectedName(0)) > -1)

ListFindList returns -1 when not found. otherwise the list index pos where it lies.
_____________________
If you'll excuse me, it's, it's time to make the world safe for democracy.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
07-16-2004 09:58
or instead of > -1
just != -1
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
Re: Re: Incorrect Test Condition in an if statement....
07-16-2004 14:31
From: someone
Originally posted by Jack Digeridoo
Try replacing this line :

if ( llListFindList( OverrideList, llCSV2List( llDetectedName(0) ) == TRUE)

with this :

if ( llListFindList( OverrideList, (list)llDetectedName(0)) > -1)

ListFindList returns -1 when not found. otherwise the list index pos where it lies.


I think the preferred form of finding an element's index in a list is by putting the element in its own list, rather then casting the element to a list.

So, the line would be:

if (llListFindList(OverrideList, [llDetectedName(0)]) != -1)

However, in this case, (list)llDetectedName(0), [llDetectedName(0)] and llCSV2List(llDetectedName(0)) are all equivelant.

The only problem I see with Tim's code, is the "== TRUE". The TRUE constant has a value of 1, so what that conditional is basicly checking for is if the index of llDetectedName in OverrideList is 1.

==Chris
Timmins Hamilton
Registered User
Join date: 15 May 2004
Posts: 68
Sorted it!
07-16-2004 22:43
Thanks for your responsed people.

There were two problems with this. First of all the syntax error acme from the brackets.... I had missed off one closing bracked from the test! Feel like a fool.

As for the actual condition, once I had the bracket and the thing would save I figured the rest out and have used the != -1.

Script now works fine, the owner can lock and unlock the door and any others who are in the list get a "X has used a key to open the door" message. All others get a "X is knocking on the door" message.