Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Useing TRUE & FALSE

Jenn Yoshikawa
Registered User
Join date: 14 Nov 2007
Posts: 91
07-30-2008 21:29
Hey guys! Little stuck on some thing. Ok what I trying to do with out useing state changes. Is if call up one command and that command would but something into TRUE. Now I have done this befor I just don't rember how I did it the right way.Here is what is happening no matter what I do IE "something = true" it still wants to use the FALSE and not the TRUE. So you have a idea of what I'm doing is. I have made my animation script witch works well. But when the owner "IE none ower of the object but owner of the sub" puts them into say kneel I'm trying to lock out the sub from useing release being the TRUE & FALSE on something.

if (something == TRUE)
{

}
else if (something == FALSE)
{

}
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
07-30-2008 21:47
You don't necessarily need to test for literal equality to TRUE or FALSE. (Those constants, BTW, are just compiler aliases for integer values 1 and 0, respectively) Some expressions which evaluate as true or false (the concepts, not the literal integer values mentioned above, hence the lower-case spelling) don't necessarily return the value 1 for a "true" result. Any non-zero value, even negative, is considered true. You may have run afoul of this, assuming a "true" result would always be TRUE (an integer value of 1).

So using your above example, instead of:

if( something == TRUE )


try using:

if( something )
{
// do this
}
else
{
// do something else
}

If the variable "something" holds any value other than zero, then the first block of code will be executed. Otherwise, "something" holds a value of zero, and the second block is executed instead. Note the "else" clause doesn't test for equality to FALSE because it is unnecessary. If something isn't true, then it must, by definition, be false, and vice versa.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
07-30-2008 21:54
nm i should read before opening my moth to insert foot :)
Jenn Yoshikawa
Registered User
Join date: 14 Nov 2007
Posts: 91
ah
07-30-2008 22:00
I seen in some script some where 1 and 0 not sure what they were useing them for now I know hehe so I would use if the owner used a command something = TRUE right?
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
07-30-2008 22:10
could be

i like to be a real pain in the butt and use numbers as statements 1 to me might == "send message" and 0 might be "reset script", but i usually document all my screweyness in the header of the script

realisticly yes most ppl who would do that would use 1 as TRUE and 0 as FALSE cause 1 and 0 are much less of a pain to type than "pinky on the caps lock and 4 letters"
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
07-30-2008 23:19
Alternative ways of coding this (a.k.a. advanced scripting knowledge):

integer a = TRUE;

if (a) { // a evaluates to TRUE
// do X
} else {
// do Y
};

the other way round:

integer b = FALSE;

if (!b) { // b evaluates to TRUE
// do X
} else {
// do Y
};

for true/false constructs, a leading exclamation mark 'negates' the value.
So, to toggle between true and false, all you do would be:

integer c = TRUE;
c = !c;
llOwnerSay((string)c);

And that should tell you either 0 or FALSE