Home   Help Search Login Register  

Author Topic: Bool == Bool Error  (Read 1755 times)

0 Members and 1 Guest are viewing this topic.

Offline Rommel92

  • Members
  • *
Bool == Bool Error
« 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?

Offline tcp

  • Members
  • *
    • Violator Gaming
Re: Bool == Bool Error
« Reply #1 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;}
« Last Edit: 19 Oct 2009, 00:03:02 by tcp »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Bool == Bool Error
« Reply #2 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).

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Bool == Bool Error
« Reply #3 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
};
try { return true; } finally { return false; }

Offline Denisko-Redisko

  • Members
  • *
Re: Bool == Bool Error
« Reply #4 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 }
sorry for my english

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Bool == Bool Error
« Reply #5 on: 01 Nov 2009, 03:09:01 »
xor, flip, flop?


Planck
I know a little about a lot, and a lot about a little.

Offline Denisko-Redisko

  • Members
  • *
Re: Bool == Bool Error
« Reply #6 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)
sorry for my english

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Bool == Bool Error
« Reply #7 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
I know a little about a lot, and a lot about a little.

Offline Rommel92

  • Members
  • *
Re: Bool == Bool Error
« Reply #8 on: 06 Nov 2009, 07:37:00 »
I found this was suffice.
Code: [Select]
(true and true) or not(true and true)