Difference between revisions of "TRUE"

From Second Life Wiki
Jump to navigation Jump to search
m
m (<lsl> tag to <source>)
 
(5 intermediate revisions by 4 users not shown)
Line 2: Line 2:
|name=TRUE
|name=TRUE
|type=integer
|type=integer
|subtype=boolean
|value=1
|value=1
|desc
|desc=Constant used to define the TRUE value in conditional structures or variables/constants in general. Usually it's used because it is more readable, indicating a [[Boolean|boolean]] value instead a [[Integer|integer]] value (1). However, this is an arbitrary distinction in LSL which uses integers to represent Boolean values anyway. It is probably better to consider TRUE and FALSE as mnemonic constants for the integer values 1 and 0.
|examples
|examples=<source lang="lsl2">integer q;
 
default
{
    state_entry()
    {
        q = TRUE;
        if(q)
        {
            llSay(0, "TRUE");
            q = FALSE;
            if(!q)
            {
                llSay(0, "FALSE");
                q = TRUE;
                if(!q)
                {
                    llSay(0, "Won't say this");
                }
                else
                {
                    llSay(0, "TRUE");
                    q = FALSE;
                    if(q)
                    {
                        llSay(0, "Won't say this");
                    }
                    else
                    {
                        llSay(0, "FALSE");
                    }
                }
            }
            else
            {
                llSay(0, "Won't say this");
            }
        }
        else
        {
            llSay(0, "Won't say this");
        }
    }
}</source>
|constants={{LSL ConstRow|FALSE}}
|constants={{LSL ConstRow|FALSE}}
|functions=
|functions=
|notes=*Note that all non-zero integers test as 'true' in statements such as "if (x) ... "  but only the value 1 corresponds to TRUE as in "if (x == TRUE) ..."
* A double exclamation mark can be used to convert any 'true' or FALSE integer to Boolean TRUE/FALSE  as in "integer Bool = !!value;"
|events=
|events=
|articles={{LSL DefineRow||[[boolean]]|}}
|articles={{LSL DefineRow||[[boolean]]|}}

Latest revision as of 17:25, 23 January 2015

Description

Constant: integer TRUE = 1;

The boolean integer constant TRUE has the value 1

Constant used to define the TRUE value in conditional structures or variables/constants in general. Usually it's used because it is more readable, indicating a boolean value instead a integer value (1). However, this is an arbitrary distinction in LSL which uses integers to represent Boolean values anyway. It is probably better to consider TRUE and FALSE as mnemonic constants for the integer values 1 and 0.

Related Articles

Constants

•  FALSE

Articles

•  boolean

Examples

integer q;

default
{
    state_entry()
    {
        q = TRUE;
        if(q)
        {
            llSay(0, "TRUE");
            q = FALSE;
            if(!q)
            {
                llSay(0, "FALSE");
                q = TRUE;
                if(!q)
                {
                    llSay(0, "Won't say this");
                }
                else
                {
                    llSay(0, "TRUE");
                    q = FALSE;
                    if(q)
                    {
                        llSay(0, "Won't say this");
                    }
                    else
                    {
                        llSay(0, "FALSE");
                    }
                }
            }
            else
            {
                llSay(0, "Won't say this");
            }
        }
        else
        {
            llSay(0, "Won't say this");
        }
    }
}

Notes

  • Note that all non-zero integers test as 'true' in statements such as "if (x) ... " but only the value 1 corresponds to TRUE as in "if (x == TRUE) ..."
  • A double exclamation mark can be used to convert any 'true' or FALSE integer to Boolean TRUE/FALSE as in "integer Bool = !!value;"

Deep Notes

Search JIRA for related Issues

Signature

integer TRUE = 1;