first problem: possible divide by zero.
obvious way to handle it?
CODE
if (x) {
llOwnerSay( (string)( y / x ) ); //-- return (y / x)
}else{
llOwnerSay( "error, undefined" ); //-- if x = 0, return error.
}
fun way to handle it? replacing zero automatically to get default values
CODE
llOwnerSay( (string)( y / (x | !x) ); //-- if x = 0, returns y.
llOwnerSay( (string)( y / (x | (!x * y)) ); //-- if x = 0, returns 1.
problem two: three way switch (negative,, zero, positive)
obvious way to handle it?
CODE
if (x) {
if (x > 0) {
llOwnerSay( "Positive" );
}else{
llOwnerSay( "Negative" );
}
}else{
llOwnerSay( "Zero" );
}
fun way?
CODE
llOwnerSay( llList2String( ["Zero", "Positive", "Negative"], (x > 0) - (0 > x) ) );
like that little trick with the list2String? it works with llGetSubstring too!
CODE
llOwnerSay( llGetSubString( "UNTRUE" , (x != 0) * 2, - 1 );
an old one that relies on an oddity of the implementation of != for lists (thanks strife)
CODE
x = (myList != []);
x = ([] != myList);
//--same as
x = llGetListLength( myList );
x = -llGetListLength( myList );
key validity?
CODE
if (vKeyTest){
//-- true if vKeyTest, Type = Key, and has a valid key
}else{
//-- false if vKeyTest has NULL_KEY or is invalid
}
index found?
CODE
if (!FindSomeIndex( thing2search, thing2look4 )){}
if (~FindSomeIndex( thing2search, thing2look4 )){}
if (!~FindSomeIndex( thing2search, thing2look4 )){}
//-- same thing as
if (FindSomeIndex( thing2search, thing2look4 ) == 0){}
if (FindSomeIndex( thing2search, thing2look4 ) != -1){}
if (FindSomeIndex( thing2search, thing2look4 ) == -1){}
have any fun tricks with conditionals that you use alot? share!