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
136
S
31
G
86
Posts: 5,487
Reputation: 59,760

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
10
S
2
Posts: 109
Reputation: 982


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests