# (solved) How would I do a Boolean comparison.

0 Favourites
• 6 posts
• So lets say you have 4 boolean instance variables, how would you trigger and event if all boolean's equaled true.

• Just AND them all together. Add the first, right-click, "Add another condition"...

• You could also do:

if you don't see exactly:

First Value:(Sprite.Boolean1 = 1) & (Sprite.Boolean2 = 1) & (Sprite.Boolean3 = 1)

Is equal to

Second Value: 1

(C2's instance variable booleans actually returns 1 if true or 0 if false)

BlackHornet's method is valid, but if you need to combine OR and AND, it could be pretty annoying to do in blocks at the end if you are good with boolean logic

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Brilliant! Oh mighty Aphrodite perfect solution. Blackhornet big thanks as well, got me thinking down the right path.

• if you don't see exactly:

First Value:(Sprite.Boolean1 = 1) & (Sprite.Boolean2 = 1) & (Sprite.Boolean3 = 1)

Is equal to

Second Value: 1

Just to clarify a bit ...

Since the Instance Variables ARE evaluated as Boolean in the expression's "logical AND" operators, the explicit comparisons "=1" are actually redundant in this case. (even if they are implemented as 1/0 for true/false "under the hood")

Actually, C2 logical comparisons, in general, appear to work with zero (0) as false and non-zero (?0) as true (rather than just 1) ...

If you're any "good with Boolean logic" the following seems even less "annoying":

(Sprite.Boolean1 & Sprite.Boolean3 & Sprite.Boolean3) =1

You DO need that last "=1" (C2 appears to have no condition for expression evaluation to Boolean ?) - you must have the "Second Value" even if it does happen to be redundant ...

Perhaps more efficient at run-time also, but I have to idea how C2 happens to optimize generated code on export ...

• You are right, the =1 were actually useless in that case (I just tends to always add it, if they would be true or false values, I would actually do the same =true, even though I know it is not needed, just a bad habit on my part, sorry about that), the second value is needed in the case of the compare two values, I do not remember if there is an evaluate expression (except for the pick by evaluate), the second value can be a not equal to 0