The OR operator is not working!

0 favourites
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • <img src="http://screensnapr.com/e/gFuZuR.png" border="0" />

    The | OR operator isn't working, it works fine when I just compare it to "block1" but when I try to compare to "block1" | "block3" it doesn't work!

  • I can't continue my game until this is fixed <img src="smileys/smiley11.gif" border="0" align="middle" /> <img src="smileys/smiley34.gif" border="0" align="middle" /> <img src="smileys/smiley28.gif" border="0" align="middle" /> <img src="smileys/smiley19.gif" border="0" align="middle" />

    The alternate way affects performance badly.

  • The OR operator doesn't do what you've assumed it to. It's a logical OR which returns either true or false. An empty string counts as false and other strings count as true. So "block1" | "block3" | "block13" | "block14" results in 'true', and you then do the comparison 'Block.AnimationName = true', which it probably isn't, so the event never runs.

  • The OR operator doesn't do what you've assumed it to. It's a logical OR which returns either true or false. An empty string counts as false and other strings count as true. So "block1" | "block3" | "block13" | "block14" results in 'true', and you then do the comparison 'Block.AnimationName = true', which it probably isn't, so the event never runs.

    Is there a way around this? Without having to use it with 4 events, There are reasons why and I don't want to go into too much detail until I release the game, I'm sadface :( <img src="smileys/smiley19.gif" border="0" align="middle" />

  • dcrew: You should take a look at the custom OR plugin.

  • dcrew: You should take a look at the custom OR plugin.

    While this plugin is great, it only seems to handle 2 different conditions, I want block1 OR block3 OR block 14 OR block 15, This won't exactly work for me.

  • It's a logical operator. You can't compare against a collection of logical or'd strings. I don't use C2, so I can't say if this is doable with the event system, but the correct way to get what you want would be:

    Block.AnimationName = "block1" | Block.AnimationName = "block3" | Block.AnimationName = "block13" | Block.AnimationName = "block14"

    This will result to true, if Block.AnimationName equals one of the four strings.

  • It's a logical operator. You can't compare against a collection of logical or'd strings. I don't use C2, so I can't say if this is doable with the event system, but the correct way to get what you want would be:

    Block.AnimationName = "block1" | Block.AnimationName = "block3" | Block.AnimationName = "block13" | Block.AnimationName = "block14"

    This will result to true, if Block.AnimationName equals one of the four strings.

    I tried that one and it says:

    <img src="http://screensnapr.com/e/9VKCCc.png" border="0" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Of course it does say so. You would have to "or" the comparisons itself. So that you have 4 comparisons in that event that are or'd. With CC you would do

    Block.AnimationName = "block1"

    OR

    Block.AnimationName = "block3"

    OR

    Block.AnimationName = "block13"

    OR

    Block.AnimationName = "block14"

    and every line is one condition (4x Comparison, 3x OR). I guess then it isn't possible to "or" conditions in C2? But in the manual it is described as if possible:

    scirra.com/manual/78/expressions/page-1

    Maybe there is "evaluate" as a system condition?

    EDIT: In general, remember that any logical operator just compares to boolean values (TRUE or FALSE) and nothing else. Those values may be replaced by expressions/conditions that result to either TRUE or FALSE (like "if a is greater b"), but it needs to be something that results in a boolean value.

  • Of course it does say so. You would have to "or" the comparisons itself. So that you have 4 comparisons in that event that are or'd. With CC you would do

    Block.AnimationName = "block1"

    OR

    Block.AnimationName = "block3"

    OR

    Block.AnimationName = "block13"

    OR

    Block.AnimationName = "block14"

    and every line is one condition (4x Comparison, 3x OR). I guess then it isn't possible to "or" conditions in C2? But in the manual it is described as if possible:

    http://www.scirra.com/manual/78/expressions/page-1

    Maybe there is "evaluate" as a system condition?

    EDIT: In general, remember that any logical operator just compares to boolean values (TRUE or FALSE) and nothing else. Those values may be replaced by expressions/conditions that result to either TRUE or FALSE (like "if a is greater b"), but it needs to be something that results in a boolean value.

    There's no OR or EVALUATE condition as I've just checked, But I guess I'll just wait for Ashley and Tom to release 74 with the fixes OR thing for this: Click Here!

  • Of course there is a conditional expression.

    Check this manual article.

    : is a conditional operator, which allows you to test conditions in expressions. This is especially useful when used with the comparison operators and logical operators. It takes the form condition ? result_if_true : result_if_false

    e.g. health < 0 | score < 0 ? "Game over!" : "Keep going!".

    The condition counts as true if it is non-zero, and false if it is zero.

    Also the bug Ashley talks about is probably not the OR condition as you expect it.

  • Of course there is a conditional expression.

    Check this manual article.

    : is a conditional operator, which allows you to test conditions in expressions. This is especially useful when used with the comparison operators and logical operators. It takes the form condition ? result_if_true : result_if_false

    > e.g. health < 0 | score < 0 ? "Game over!" : "Keep going!".

    > The condition counts as true if it is non-zero, and false if it is zero.

    Also the bug Ashley talks about is probably not the OR condition as you expect it.

    Are you on topic here? I want to run the event IF the AnimationName of Block is any of the 4 following strings.

  • Hmm, there might be an operator precedence bug - does this work?

    (Block.AnimationName = "block1") | (Block.AnimationName = "block3") | (Block.AnimationName = "block13") | (Block.AnimationName = "block14")

  • Hmm, there might be an operator precedence bug - does this work?

    (Block.AnimationName = "block1") | (Block.AnimationName = "block3") | (Block.AnimationName = "block13") | (Block.AnimationName = "block14")

    nope.

  • Ashley

    Confirmed. The expression editor won't take an expression like

    "red"="red"

    It says "type mismatch, = does not work with 'integer' and 'string' (use & to build strings)"

    dcrew

    You can use a private variable to combine picking across events to do an "or".

    http://dl.dropbox.com/u/5426011/examples%208/or_example.capx

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