How do I create an AND & OR block in same event

Just started using Construct 2? Post your questions here

» Sat Oct 17, 2015 9:19 pm

What I am trying to do in a single event is this:

if THIS1 OR (THIS2 AND THIS3) then... do something

If I make an event an OR block then it seems I cannot create AND conditions anymore. I know how to solve this with subevents but that would require me duplicating the actions for THIS1 and then THIS2 AND THIS3.
B
88
S
30
G
11
Posts: 101
Reputation: 11,187

» Sun Oct 18, 2015 12:02 am

If you can't put the "and" part as a sub-event to the "or" part, You can use a boolean trick.

the following is: If This1="a" or (This2="a" and This3="a")

Under system, use the event "Compare two values"

First Value:
(This1="a") + ((This2="a") * (This3="a"))

the comparison is "Greater than or Equal"

value to compare to is 1

The equation in parenthesis is a boolean value, if true then the value is 1 which is what "true" equals, if it were false, the value is 0.

So if the first field, (This1="a"), is true, it will be 1.

If both the other are true, they both equal 1, so 1 times 1 is 1 as well. If either is false, then 1 times 0 will be 0.
both results are added together so anything over 1 means the statement found a positive result and performs the actions.

Does that do what you need?
B
248
S
65
G
34
Posts: 906
Reputation: 41,349

» Sun Oct 18, 2015 1:50 am

However, the conditions I'm using aren't simple expressions - they are Keyboard and/or Touch conditions. I am, not sure if it is possible to do something like "If right arrow key is down" in the first field. So, my solution is to set a boolean every time the right arrow key is pressed. Would this be an alright solution?
B
88
S
30
G
11
Posts: 101
Reputation: 11,187

» Sun Oct 18, 2015 2:19 am

Hmm, could you

This1="a" | call function a
else
This2="a"
This3="a" | call function a

?

Use an else instead of an Or, you have to repeat the actions, but they only get called once
B
248
S
65
G
34
Posts: 906
Reputation: 41,349

» Sun Oct 18, 2015 5:25 am

I could - I was just trying to avoid having to call the actions multiple times. Is this a limitation of C2 btw? I'm thinking OR blocks shouldn't make the entire event use OR's but instead be condition specific.
B
88
S
30
G
11
Posts: 101
Reputation: 11,187

» Sun Oct 18, 2015 5:32 am

@Badmiracle It really depends to be honest, could you give a little more context of what you are checking for the event?

I use lots of approaches for these types of events but it really depends on what type of actions or things it is needing to check. But generally I use different variables when "something is happening or is pushed" and can use it in other events to check if it is 1 or 0, etc.

Learn to make a clicker game for cheap!
https://www.scirra.com/store/games-with ... e-game-666

Try out Pixel Golf on the Scirra Arcade!

Pudgy Platypus Games website!
www.pudgyplatypus.com
B
60
S
21
G
5
Posts: 212
Reputation: 7,515

» Sun Oct 18, 2015 5:55 am

@Djfuzion Sure. I am trying to add Mobile controls to a game that would otherwise be played on a PC using the Keyboard. So for movement I have:

Right key is down OR (Touch.X > LayoutWidth/2 AND Is in touch) Then
... Do stuff for moving right

Left key is down OR (User Touch.X < LayoutWidth/2 AND Is in touch) Then
... Do stuff for moving left

etc.

The reason I have to include "Is in touch" is because it appears that Touch.X may be true even if Is in touch is not..
B
88
S
30
G
11
Posts: 101
Reputation: 11,187

» Sun Oct 18, 2015 11:35 am

when touch is not touching, touch.x = 0 and touch.y = 0

so using a simple "is between values" should work in this case..

You could ofcourse also use collodium's trick by setting a variable to 1 on touch start and back to 0 on touch end and doing something similar for the keyboard..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Who is online

Users browsing this forum: No registered users and 1 guest