Create "OR AND" statement?

0 favourites
  • 10 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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:

    <img src="http://i.imgur.com/D5Chp.png" border="0" />

    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:

    <img src="http://i.imgur.com/33pMJ.png" border="0" />

    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 <img src="smileys/smiley17.gif" border="0" align="middle" />

  • 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. :)

    <font size="1">...might be 11 bazillion</font>

  • 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.

  • Arima: Ah, good to know I'm not going crazy <img src="smileys/smiley1.gif" border="0" align="middle">.

    I'll use a local variable for now, I'll just try not to let Uncle Bob find out <img src="smileys/smiley1.gif" border="0" align="middle">

    Thanks mate!

    Ashley: Is there any chance of this being incorporated into C2?

  • boolean

    Since no picking occurs in your example you can do it with:

    System compare (a=b) | ((b=c) & (c=a)) = 1

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

    What was an issue was my inexperience designing code properly, which is how it turned into a tangled mess.

    <img src="http://www.amirai.net/forums/Renaesad.png" border="0" />

    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.

  • Or put an else in event 2.

    a == b

    else

    b = c

    c = a

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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. <img src="smileys/smiley1.gif" border="0" align="middle" />.

    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.

  • 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!

  • 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. <img src="smileys/smiley1.gif" border="0" align="middle" />..

    Lol nice save XD

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)