Create "OR AND" statement?

Get help using Construct 2

Post » Sat Jan 05, 2013 8:54 pm

Hi all

I might be a moment of stupidity but I'm trying to figure out how to do the following: (this is just sample code):

if((a==b) || (b==c && c==a)) {
MoveSprite();
}


I tried doing this in C2 - here is a screenshot:



which is actually the equivalent of:

if(a==b){
MoveSprite();
}

if (b==c && c==a){
MoveSprite();
}


The problem is that now when a==b and c==a, C2 fires on both conditions, as opposed to my one condition in the sample code. What I want to do is say "if the first condition block OR the second condition block", but since I can only do OR statements on single condition blocks it doesn't cover both cases.

Ideally I would want to do something like this:


Is there a way of achieving this? I feel like I must be missing something obvious or else people like Arima with their 10 bazillion event super-games would have run into this a while ago boolean2013-01-05 20:56:55
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Sat Jan 05, 2013 9:38 pm

The way I deal with it is I have a local or global 'or' variable before both events that first is set to 0, then gets set to 1 if the first event runs. Then check in the second event if the variable is one or zero.

So yeah, I have run into that situation before. :)

...might be 11 bazillionArima2013-01-05 21:43:53
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sat Jan 05, 2013 9:52 pm

The other way I think, would be to have..

+ System a = b
+ System b = c (INVERTED)
+ System c = a (INVERTED)
..
+ System a = b (INVERTED)
+ System b = c
+ System c = a

unless you have many many conditions to check. Arima's is definitely the way to go in that case.
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Sat Jan 05, 2013 9:52 pm

@Arima: Ah, good to know I'm not going crazy .

I'll use a local variable for now, I'll just try not to let Uncle Bob find out

Thanks mate!

@Ashley: Is there any chance of this being incorporated into C2?
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Sat Jan 05, 2013 10:34 pm

@boolean
Since no picking occurs in your example you can do it with:
System compare (a=b) | ((b=c) & (c=a)) = 1
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Sat Jan 05, 2013 10:41 pm

Are you implying that loot pursuit's code is some kind of mess -

[QUOTE=Arima]What was an issue was my inexperience designing code properly, which is how it turned into a tangled mess.[/QUOTE]



Seriously though, I think Ashley said that it wasn't feasible to have c2 have multiple conditions for each section of an or block because of the way construct is designed.

Edit: or you could use the better suggestions listed above and below this post.Arima2013-01-05 22:43:37
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sat Jan 05, 2013 10:42 pm

Or put an else in event 2.

a == b

else
b = c
c = a
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sat Jan 05, 2013 11:22 pm

@R0J0hound = Very cool. I didn't know you could do OR statements right in the code! There are some sections I am picking (mainly for If overlapping X or overlapping Y and Z type logic). But still, very good to know.

@Arima: Oh haha, mmm, let's see if I can dig myself out of that hole. I bet your code is amazing! And your fashion sense is impeccable! Yes, there we go. .

In regards to C2 not being able to support it, fair enough. I get the feeling that little things like this seem easy to implement, but there enough C++ code running under C2 by now to make the moon landing look trivial.

@ramones: Very sneaky. I'll give that a shot. That should over most of my situations I think.boolean2013-01-05 23:25:51
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Sun Jan 06, 2013 12:40 am

Ugh coming from CC, I forgot about Else since it was a huge problem with CC. Good to know it's ok to use in C2!
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Sun Jan 06, 2013 1:07 am

[QUOTE=boolean]@Arima: Oh haha, mmm, let's see if I can dig myself out of that hole. I bet your code is amazing! And your fashion sense is impeccable! Yes, there we go. ..[/QUOTE]

Lol nice save XD
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Next

Return to How do I....?

Who is online

Users browsing this forum: Televangelist and 27 guests