OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: Rommel92 on 18 Oct 2009, 03:38:45

Title: Bool == Bool Error
Post by: Rommel92 on 18 Oct 2009, 03:38:45
I have a solution, simply convert the bools to strings and then compare them, but why does this error like this? I always viewed comparisons as Boolean logic anyway?
Title: Re: Bool == Bool Error
Post by: tcp on 18 Oct 2009, 05:55:39
To me it makes since because unless it's converted to a string, then the booleans will always be compiled as true or false.
if(_bool1 && _bool2) then {_bothtrue=true;}
if(!(_bool1 || _bool2)) then {_bothfalse=true;}
Title: Re: Bool == Bool Error
Post by: Mandoble on 18 Oct 2009, 23:31:45
tcp, while you are technically right, equal or not equal comparisons between booleans are commonly used in any language (well, except this).
Title: Re: Bool == Bool Error
Post by: Worldeater on 31 Oct 2009, 16:30:30
Another thing to keep in mind is that if you have a single boolean you don't have to compare it to anything:

Code: [Select]
_isTrue = true;

if _isTrue then {
  // do something in case it's true
};

if not _isTrue then {
  // do something in case it's false
};
Title: Re: Bool == Bool Error
Post by: Denisko-Redisko on 01 Nov 2009, 01:26:41

Code: [Select]
#define xor(A,B)    (!(A && B) && (A || B))
// example
if( xor(flip, flop) ) then { flop = !flop }
Title: Re: Bool == Bool Error
Post by: Planck on 01 Nov 2009, 03:09:01
xor, flip, flop?


Planck
Title: Re: Bool == Bool Error
Post by: Denisko-Redisko on 01 Nov 2009, 16:23:40
Planck, yes, using xor possible to compare boolean values:

Code: [Select]
(true xor true) === (true != true) === false
(false xor false) === (false != false) === false
(false xor true) === (false != true) === true
(true xor false) === (true != false) === true

A xor B === (A or B) and (not A or not B)
A xor B === (A and not B) or (B and not A)
A xor B === (not (A and B)) and (A or B)
Title: Re: Bool == Bool Error
Post by: Planck on 01 Nov 2009, 16:41:42
ok, I understand, I thought you meant there was an actual xor operator in the commands list.


Planck
Title: Re: Bool == Bool Error
Post by: Rommel92 on 06 Nov 2009, 07:37:00
I found this was suffice.
Code: [Select]
(true and true) or not(true and true)