Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

ORing a detectedName

Perwin Rambler
Registered User
Join date: 24 Mar 2005
Posts: 152
07-13-2005 14:04
I am trying to have a script do a if statement that compares the llDetectedName two 2 hardcoded names.

I have
if (llDetectedName(i) == "first1 last1" || "first2 last2" )
{
}

This thould work as I understand it.

if I take out the OR and the second name it compiles fine.
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
07-13-2005 14:18
What you have is basically:
CODE
if ( (llDetectedName(i) == "first1 last1") || "first2 last2" ) {
// ok
}

The result of || is true or false depending on the true/false value of its operands, so using parentheses to make it ("first1 last1" || "first2 last2";) wouldn't do what you want either.

What you want is something like:
CODE
if ( (llDetectedName(i) == "first1 last1") || (llDetectedName(i) == "first2 last2") ) { 
// ok
}


Another, more flexible way to do it, uses llListFindList:
CODE
if ( llListFindList(["first1 last1", "first2 last2"], [llDetectedName(i)]) != -1 ) {
// ok
}


You could then move the list to a variable at the top of your script to make it easier to change, easier to drop into other scripts, and easier to change within the script (for example with a voice command) if you decide you want to do that someday:
CODE

list ALLOWED_NAMES = ["first1 last1", "first2 last2"];
// ...
if ( llListFindList(ALLOWED_NAMES, [llDetectedName(i)]) != -1 ) {
// ok
}
Perwin Rambler
Registered User
Join date: 24 Mar 2005
Posts: 152
thank you
07-13-2005 14:25
yeah I know about using the list option.

but I wanted to have just 2 names and figured it a waste.


but thanks again.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
07-13-2005 16:42
this will run faster and save bytecode (at the expense of some memory)

CODE

string name = llDetectedName(i);
if (name == "first1 last1" || name == "first2 last2" )
{

}
_____________________
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