(solved) How would I do a Boolean comparison.

Get help using Construct 2

Post » Thu May 15, 2014 11:38 pm

So lets say you have 4 boolean instance variables, how would you trigger and event if all boolean's equaled true.
Last edited by dthomasdigital on Fri May 16, 2014 2:14 am, edited 1 time in total.
B
25
S
10
G
3
Posts: 154
Reputation: 2,838

Post » Fri May 16, 2014 12:00 am

Just AND them all together. Add the first, right-click, "Add another condition"...
ImageImageImage
B
71
S
21
G
220
Posts: 3,648
Reputation: 123,725

Post » Fri May 16, 2014 12:19 am

You could also do:

Image

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
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Fri May 16, 2014 2:14 am

Brilliant! Oh mighty Aphrodite perfect solution. Blackhornet big thanks as well, got me thinking down the right path.
B
25
S
10
G
3
Posts: 154
Reputation: 2,838

Post » Tue Jul 01, 2014 4:03 am

Aphrodite wrote: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

[Edit]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 ...
B
7
Posts: 7
Reputation: 291

Post » Tue Jul 01, 2014 11:34 am

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
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093


Return to How do I....?

Who is online

Users browsing this forum: MainFable, newday198913 and 5 guests