Don't click here unless you want to be banned.
LSL Wiki :
Boolean
HomePage
::
PageIndex
::
RecentChanges
::
RecentlyCommented
::
UserSettings
:: You are crawling22.us.archive.org
=====Boolean===== //Boolean// [[operators]] behave like other operators such as ""+"", ""-"", ""*"", ""/"" etc except the inputs and output can only take on two values. These values can be represented as [[TRUE]] and [[FALSE]] or 1 and 0 although any non zero value will generally be treated as TRUE. Unlike most modern programming languages with optimizing [[compiler]]s, **the boolean operators in [[LSL]] do not short-circuit**. In C, for example, when using **""||""**, if the [[condition]] on the left turns out to be true, the computer does not even evaluate the condition on the right; there is no need because we can already tell that the **""||""** will return ##TRUE##. Similar logic works for **&&**: if the first condition is false, there is no need to evaluate the other condition because the **&&** must return ##FALSE##. This leads to speedups in complicated conditionals. LSL **does not** do this, so if you're expecting it, it may make your [[code]] less efficient, or worse yet, incorrect if you're expecting a function in the second half of an **""||""** or **&&** not to be called. Also, unlike the most programming languages, LSL evaluates conditions **right to left**, so in ##(getVar1() && getVar2())## function ##getVar2()## is run before ##getVar1()##. ===Boolean Operators=== **Note:** Operators that expect boolean [[value]]s from [[integer integers]] (##TRUE## or ##FALSE##) will treat all non-zero values as ##TRUE##. |||c **Operator** || **Name** || **Syntax** || **Description** || || **&&** || AND || ##**var1 && var2**## ""<br>""|| Returns ##TRUE## if ##var1## and ##var2## are both ##TRUE##, ##FALSE## otherwise. ""<br>""##var1## and ##var2## must both be integers.|| || **""||""** || OR || ##**var1 ""||"" var2**## ""<br>""|| Returns ##TRUE## if either ##var1## or ##var2## are ##TRUE##, ##FALSE## otherwise. ""<br>""##var1## and ##var2## must both be integers.|| || **!** || NOT || ##**!var1**## || Returns ##TRUE## if ##var1## is ##FALSE##, or ##FALSE## if ##var1## is ##TRUE##. ##var1## must be an integer.||| **Note:** -When using **##""==""##** or **##!=##** on [[list lists]], it's important to remember that only the list lengths are compared. So "##["a"] ""=="" ["b"]##" would return ##TRUE##, the same as "##llGetListLength(["a"]) ""=="" llGetListLength(["b"])##". -Do not confuse the [[assignment]] operator "=" with the equality operator """=="""! When comparing two values, use """==""". When //assigning// a value, use "=". The compiler will not catch your error, as it's possible to assign values within an IF statement delibeartely. Compiling a script with "=" rather than """==""" will probably cause the statement to evaluate to ##TRUE## and the conditional variable to become corrupted. -Unlike most languages, in LSL the **""||""** operator takes precedence over the **&&** operator. Thus, this expression: (TRUE && TRUE ""||"" FALSE && FALSE) will evaluate as FALSE, as it is reduced to (TRUE && TRUE && FALSE). These operators are often used in [[ifelse conditional statements]]. **Q**: ''How do you have a boolean XOR?'' **A**: ''Use an ##if()## statement:'' %%(lsl) if((1 || 0) && !(1 && 0)) //if((they are either T and F or T and T) AND (are NOT T and T)) %% ---- [[Operators]] | [[Unary]] | [[Binary]] | [[Bitwise]] | [[Boolean]] | [[Equality]] | [[Assignment]]
Valid XHTML 1.0 Transitional
::
Valid CSS
:: Powered by
WakkaWiki 0.1.2