View Single Post
08-26-10, 11:57 AM   #6
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
Split them up and go through them step by step - note the parentheses!

Code:
CNames_Options.enemy = (CNames_Options.enemy == nil) and true or CNames_Option.enemy
Is basically the same as my if-conditional code, just inline.

(CNames_Options.enemy == nil)
- when true: true == nil --> false
- when false: false == nil --> false
- when nil: nil == nil --> true

So, if the result is true (only in case of nil == nil), CNames_Options.enemy is defined true (' and true'), otherwise it holds its previous value (' or CNCNames_Options.enemy').

-----
Same applies to
Code:
CNames_Options.enemy = not (CNames_Options.enemy == false)
(CNames_Options.enemy == false)
- when true: true == false --> false
- when false: false == false --> true
- when nil: nil == false --> false

The result is then inverted (NOT).
So, if your variable holds true/nil, the result of the comparison is 'false' (as you can see above) and your variable gets set to NOT false --> true.
And when 'false', comparison says 'true', so NOT makes it 'false' again.

-----
I prefer Fodaro's / my example, because they imho are more transparent to the reader.
__________________
« Website | GitHub »

Oh hai!

Last edited by xConStruct : 08-26-10 at 12:00 PM.
  Reply With Quote