How do I play animation based on Global NR?

Get help using Construct 2

Post » Wed Jan 18, 2017 3:05 pm

Greetings there! ^_^
So i have about 55 animations that needs to be played, depending on *items*.
Now, it is a bit too long to do;

''When button Q is pressed''
''If (Global Variable is 1) = Play animation 1.
''If (Global Variable is 2) = Play animation 2.
''If (Global Variable is 3) = Play animation 3.

And so on, and so on.

So my question is, can animation be played by a Global Variable number? For example;
'When Q button is pressed''
''Set animation to *(the variable)*''

So if variable is 1, it plays animation 1, if the variable is 2 then play animation 2 and so on? Or do i have to take the long way by IF and do's?

Thanks alot ^_^
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Wed Jan 18, 2017 3:53 pm

Basically to play Animation 1 if Variable is 1
Play animation 2 if Variable is 2. Etc
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Wed Jan 18, 2017 4:09 pm

Yes, I do this all the time. What I do is make the value of the variable the same as the animation name, then you can make an event like this:
On Q pressed set player var_animation to "animationname"

(whatever trigger you like) set player animation to player.var_animation
or
If player var_animation="walkleft" set animation to player.var_animation
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,991

Post » Wed Jan 18, 2017 6:33 pm

Burvey wrote:Yes, I do this all the time. What I do is make the value of the variable the same as the animation name, then you can make an event like this:
On Q pressed set player var_animation to "animationname"

(whatever trigger you like) set player animation to player.var_animation
or
If player var_animation="walkleft" set animation to player.var_animation


Hehe hey, this is so good to hear!! But i dont quite understand what u mean.

When character jump, depending on item equipped, a different animation plays (on the effect)

So as far as i understand it, the Variable has to be the same name as the effect right?

So ability name: BootsFX
Global Variable name: BootsFX
If player equips Boot 2 -> Set BoostFX (Variable) to 2.
If player equips Boot 5 -> Set BoostFX (Variable) to 5.

When HeroX performs ''jump'' - Set animation to BoostFX? The variable that is?
(If the boots equipped is Boot 2 (BoostFx2) - If i play the Animation in Variable, will it be BoostFx2 Effect??
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Wed Jan 18, 2017 8:47 pm

There are literally dozens of ways to do this. You'll need to experiment and find the way that works the best for you. I've put together a capx of one way for you to hopefully get you started.

https://www.dropbox.com/s/ox5igc3xe1bin ... State.capx

EDIT: I just noticed that you said you wanted an effect animation to change, not the player animation. In that case, you would do it the exact same way as shown in the capx, just add the variable etc to the effect sprite rather then the players. I've updated the above capx with an example.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,991

Post » Wed Jan 18, 2017 10:15 pm

Burvey wrote:There are literally dozens of ways to do this. You'll need to experiment and find the way that works the best for you. I've put together a capx of one way for you to hopefully get you started.

https://www.dropbox.com/s/ox5igc3xe1bin ... State.capx

EDIT: I just noticed that you said you wanted an effect animation to change, not the player animation. In that case, you would do it the exact same way as shown in the capx, just add the variable etc to the effect sprite rather then the players. I've updated the above capx with an example.


Hehe hey!! Gotcha now!! ^_^ - Thanks alot for this!! You really took your time man, very much appreciated!! ^_^
Thanks! :D
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Thu Jan 19, 2017 4:20 am

You're welcome. If you have any issues relating to this, feel free to get in contact with me. I've already worked through most of them myself and I would be happy to help if needed.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,991


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests