Expression for several triggers

  • I have an event that should react to 3 different anims of the sprite, doesn't matter which of those is playing.

    Is there a way to make this short with expressions?

    something like:

    -when X sprite is playing anim ("1","2","3"), makes this stuff happen.

    The ( ) should represent "any of the anims in here".

  • anyone?

    at least to know if this is possible or not and to avoid having 3 events where I could have just 1.

  • you can use the "or" block.

    make the three event, select them , right click : make "or" block.

  • hmm yes, I know the OR. I've been trying it but sometimes brings many problems and makes the code a little harder to read.

    Is it possible to make what I said in the first post? If not then it's ok. just want to know that...

  • | is a logical OR operator

    put it between the animationnames and it might work.

  • Something like TokenAt?

    https://www.scirra.com/manual/126/system-expressions

    (under the Text section)

  • Yup you can do it as an expression like LittleStain said using |

    But the example asked is not much different than an OR Block.

    example. Sprite has at least the following animations "a1" "a2" "a3"

    and you wanted to do something if any of the 3 were playing.

    As an OR block you would do this.

    <img src="https://dl.dropboxusercontent.com/u/3285817/screenshots/other/onzephyr_exp_ex2.png" border="0" />

    you could also do it as an expression but the "is playing" event can't except expressions using | as far as I can tell so you have to use a "system compare two values" event. You Will also need to add a "For Each event" if more then one "Sprite" object exists.

    <img src="https://dl.dropboxusercontent.com/u/3285817/screenshots/other/onzephyr_exp_ex1.png" border="0" />

    Either way it visually takes up about the same space. If you just don't like really large OR Blocks. Put them inside a group. that way you can collapse it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • well, the thing about OR blocks is that sometimes I have to use more "or" stuff.

    for example I have 3 different animations that I use as triggers, that could be used in an OR block. but then, in some cases, I need more triggers like if it's mirrored or not. So that would need some kind of another OR block. That's why I needed this alternate way.

    What I finished doing was adding a variable that activates whenever any of those anims are playing in an OR block.

    about the tokenat, sadly I really didn't understand a single thing about it:

    ---------

    tokenat(src, index, separator)

    Return the Nth token from src, splitting the string by separator. For example, tokenat("apples|oranges|bananas", 1, "|") returns oranges.

    ----------

    it's like chinese for me. Why would it return oranges? i you want it to return oranges just write oranges. anyway, can't understand it.

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