How do I combine "And" and "Or" blocks in an event?

Get help using Construct 2

Post » Sun Dec 06, 2015 5:20 am

I'd like to select 2 objects in the same event and was trying to do something similar to the following:

(Cell.Column = GemX2 AND Cell.Row = GemY2) OR System.Pick.GemFamily.instance(0)

But I'm finding that as soon as I include the "OR" into the event all the conditions use an "OR" operator. How do I accomplish selecting both a cell object and a Gem object using a pick index n and 2 local variable comparisons to gem instance variables so that the action has both the gem and the cell in scope?

Thanks for your help!

Ben
B
18
S
7
G
2
Posts: 19
Reputation: 1,863

Post » Sun Dec 06, 2015 6:33 am

I wound up splitting the predicate from the first and condition from the predicates of the or condition into 2 event blocks and just storing the index of the first object in a local variable to be used in the second action of the second event. This seems like a hokey and cumbersome way to achieve what I'm trying to do. But pragmatically it works. I'd love to hear of a more elegant solution if someone has one.

Thanks!

Ben
B
18
S
7
G
2
Posts: 19
Reputation: 1,863

Post » Sun Dec 06, 2015 9:05 am

bholtzman wrote:I wound up splitting the predicate from the first and condition from the predicates of the or condition into 2 event blocks and just storing the index of the first object in a local variable to be used in the second action of the second event. This seems like a hokey and cumbersome way to achieve what I'm trying to do. But pragmatically it works. I'd love to hear of a more elegant solution if someone has one.

Thanks!

Ben


Isn't what you require covered in THIS section of the manual?
If your vision so exceeds your ability, then look to something closer.
Moderator
B
147
S
33
G
89
Posts: 5,984
Reputation: 62,783

Post » Sun Dec 06, 2015 5:57 pm

I do see this text in the manual, "You can combine the block types by using sub-events. This allows you to build up more advanced logic, such as an 'Or' block followed by an 'And' block." But from my understanding the first condition will filter out what I'm trying to pick in the second condition. Maybe my understanding is wrong, but I'm thinking that what happens is that each event will select a group of objects and each sub event will select a group of objects selected from the parent event. Very much like method chaining in other programming languages. If this is the only way event/sub-event object scope works then I can't achieve what I'm trying to do. But if there's a way to get the parent to select from a global scope of all objects followed by the sub-event selecting from all global objects while not filtering out the selection from the parent object, then what I'm trying to do might work. I did notice the System.Pick events, which are probably what I need to achieve my goals. I'd love to understand this better, so please correct me of I'm wrong.

Thanks,

Ben
B
18
S
7
G
2
Posts: 19
Reputation: 1,863

Post » Sun Dec 06, 2015 6:42 pm

Ok, I think I see a way to accomplish what I'm after without using the temp variables. I think the original logic here:

(Cell.Column = GemX2 AND Cell.Row = GemY2) OR System.Pick.GemFamily.instance(0)

can be rewritten to something like this:

(Cell.Column & ", " & Cell.Row = GemX2 & ", " & GemY2) OR System.Pick.GemFamily.instance(0)

This is still not a great solution as it's not as readable/maintainable as it could be. But it's better.
B
18
S
7
G
2
Posts: 19
Reputation: 1,863

Post » Sun Dec 06, 2015 7:18 pm

Your confusion is valid, since Construct 2 does not allow mixing of AND and OR together.

Suppose you have to do something when [ A = true AND B = true ] OR C = true,

My solution to the above problem, using Construct 2 event sheet, would be:

------------------
 A = true              [Do something]
 B = true
------------------
   | Else                [Do something]
   | C = true
   |---------------
B
13
S
3
Posts: 122
Reputation: 1,187

Post » Sun Apr 01, 2018 8:43 pm

I have similar problems... but i have two 'OR' conditions plus an 'AND'
i'm new to construct 2 having previous experience in basic languajes.
I can't belive that construct 2 is so easy to manage and make games really faster but a simple expression like this:
'IF (a OR b) AND c' is giving me headaches to make it work (if it is possible, guess it is)
Yes i know i have to RTFM just commenting... it's so frustating.
B
9
S
3
G
13
Posts: 11
Reputation: 7,818

Post » Mon Apr 02, 2018 1:51 am

@SERGIOManOwaR
Use System-> Compare two values
((a | b) & c) equals 1
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,371
Reputation: 84,369

Post » Mon Apr 02, 2018 2:26 am

@SERGIOManOwaR In this case, and due to how events work, have your main event be a OR block, and then have a sub-event checking C.
In this sub-event, have your actions.

The first event will be checked and if either the first or second condition is true, it will then check for the sub-event. If the condition of the sub-event is true, it will then execute the actions which logically is pretty much : "If A or B is true AND C is true then do stuff".

If any of the conditions are false, then the actions won't be executed.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
312
S
129
G
101
Posts: 7,426
Reputation: 75,376

Post » Tue Apr 03, 2018 12:15 am

Thanks for response i thoght this was dead...
dop200 i will chek that thanks!
Kyatric thats what i'm currently doing but it works sometimes and sometimes not, i don't know why.
for testing purposes, i made a main event make it 'OR' block containing 'any touch start' OR 'any key pressed' then a sub-event 'key SPACE pressed" then in the subevent block put a goto next layout.... whay i expected to do is this:
Any touch (mobile or clik) OR any key...AND space key.. goto next layout... surprisingly it does not work exactly.... first condition works... if you touch OR press key causes no effect unless you have also pressed space key.. so far so good! But the surprise comes when you press space without touching or pressing key.. and it also triggers goto next layout!

...
However in the game i'm currently doing i make another similar structure to compare in an "OR" block several conditions that causes game over and a sub-event to chek if game-over events are actually disabled, then enable.
And in this case, this combination of (a OR b OR c) AND d works fine!
I'm on it i'm learning my own, don't worry.. thank you very much for feedback.. just wanted to post something cos i'm new to C2, greetings!
B
9
S
3
G
13
Posts: 11
Reputation: 7,818

Next

Return to How do I....?

Who is online

Users browsing this forum: urkokan and 8 guests