Expression for several triggers

Get help using Construct 2

Post » Fri Oct 11, 2013 2:03 am

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".
B
5
S
1
Posts: 92
Reputation: 609

Post » Fri Oct 11, 2013 9:05 pm

anyone?
at least to know if this is possible or not and to avoid having 3 events where I could have just 1.
B
5
S
1
Posts: 92
Reputation: 609

Post » Fri Oct 11, 2013 9:10 pm

you can use the "or" block.
make the three event, select them , right click : make "or" block.
B
19
S
5
Posts: 104
Reputation: 1,761

Post » Fri Oct 11, 2013 10:52 pm

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...
B
5
S
1
Posts: 92
Reputation: 609

Post » Fri Oct 11, 2013 11:02 pm

| is a logical OR operator

put it between the animationnames and it might work.
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

Post » Fri Oct 11, 2013 11:03 pm

Something like TokenAt?

https://www.scirra.com/manual/126/system-expressions
(under the Text section)
B
240
S
62
G
33
Posts: 903
Reputation: 40,589

Post » Sat Oct 12, 2013 12:02 am

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.


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.


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.onzephyr2013-10-12 00:04:40
B
88
S
14
G
9
Posts: 101
Reputation: 9,962

Post » Sun Oct 13, 2013 11:51 pm

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.
B
5
S
1
Posts: 92
Reputation: 609


Return to How do I....?

Who is online

Users browsing this forum: jogindarpradeep, matriax and 17 guests