How do I set states with variables? Not sure what's wrong

Get help using Construct 2

Post » Sun Jun 22, 2014 10:23 pm

I just noticed that Sprite has triggers to check if animations are finished.

Just have an instance variable on your enemy object "isCurrentlyAttacking" which you set to 1 when you start each animation, and have a subevent just below the 'enemystate = "attack"' condition to check for "enemy on any finished" with an action to set "isCurrentlyAttacking" to 0. You only start an animation if "isCurrentlyAttacking" is equal to 0

(I didn't see the condition before because I was testing below another trigger, so it didn't show)
B
6
S
2
Posts: 79
Reputation: 608

Post » Sun Jun 22, 2014 11:02 pm

:deleted last post, I think I got it working: Does this look right? Thank you very much!


enemyattack2.png
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 37
Reputation: 276

Post » Mon Jun 23, 2014 2:37 am

Joy wrote::deleted last post, I think I got it working: Does this look right? Thank you very much!


enemyattack2.png


The last 3 events should be subevents of the first one, because if not you'll have them starting the animations even if they're not in the "attack" state. Aside from that, it should work perfectly

Tell me how it goes
B
6
S
2
Posts: 79
Reputation: 608

Post » Mon Jun 23, 2014 2:48 am

In fact, you could transform those last 3 events into only one, if you keep the names of the animations in an array and then do

enemy_bbox isCurrentlyAttacking = 0 -> enemy Set animation to AnimationArray.At(int(random(3)) (play from beginning)
----------------------------------------------------- -> enemy_bbox set isCurrentlyAttacking = 1
B
6
S
2
Posts: 79
Reputation: 608

Post » Mon Jun 23, 2014 3:02 am

It actually worked without making the last three events a subset of the first one, but I did it anyway because that could cause trouble later. Thank you very much!

I'm not quite familiar with arrays yet, but I will make a note of what you wrote and try to put it to use later. Thanks for that too!

One additional problem came up during the attack animation playback mess, but I hate to keep asking questions. :oops: In that large code example earlier, it shows the enemy will move towards the player's bounding box by checking X, moving, and playing the walking animation. The only thing is that in this case, the animation does not get interrupted when the enemy overlaps the player's bounding box, and enemy pauses to finish its four frame walking animation before the enemystate is set to "attack". I tried putting Stop animations, Trigger Onces, etc, but whenever they do work, they also stop the random attacks from beginning. Do I need to make another variable in order to cut off animation immediately?

Again, thanks a lot for your time. I hope that this discussion and your advice will help other users too.
B
4
Posts: 37
Reputation: 276

Post » Mon Jun 23, 2014 3:07 am

Where did you try using Stop Animation?
B
6
S
2
Posts: 79
Reputation: 608

Post » Mon Jun 23, 2014 3:14 am

As an action for enemy_bbox is overlapping player_box (and I don't know why there were two of those 'overlapping playerbbox' there, I removed one).
B
4
Posts: 37
Reputation: 276

Post » Mon Jun 23, 2014 3:32 am

Joy wrote:As an action for enemy_bbox is overlapping player_box (and I don't know why there were two of those 'overlapping playerbbox' there, I removed one).


Strange, it should work there
B
6
S
2
Posts: 79
Reputation: 608

Post » Mon Jun 23, 2014 5:07 am

Here's where I put it, is this still correct? The logic seems to make sense to me, but the enemy always plays all four animation frames before switching to enemystate "attack".

stopanimation.png



Could you tell me where I could find in the manual (or elsewhere) how to write the expression for checking if any of a number of animations have finished? Basically I want to do something like:

Enter the name of the animation that has finished: Animation: "enemykick1", "enemypunch1","enemypunch2" (that doesn't work of course)


I seem to be able to find everything I don't need to know, but never what I do. ;)
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 37
Reputation: 276

Post » Mon Jun 23, 2014 5:57 am

Joy wrote:Here's where I put it, is this still correct? The logic seems to make sense to me, but the enemy always plays all four animation frames before switching to enemystate "attack".

stopanimation.png



Could you tell me where I could find in the manual (or elsewhere) how to write the expression for checking if any of a number of animations have finished? Basically I want to do something like:

Enter the name of the animation that has finished: Animation: "enemykick1", "enemypunch1","enemypunch2" (that doesn't work of course)


I seem to be able to find everything I don't need to know, but never what I do. ;)


I think I found the problem. You should put the overlapping condition before the other two, and use System -> Else.

Most of the time, if two sprites are overlapping, their X coordinates aren't necessarily equal, so, for example, let's say that your enemy is already walking right towards the player when you enter the base level event, and enemy_bbox is overlapping player_bbox, but is still a little to the left (enemy_bbox X < player_bbox.X). You first enter the "enemywalkR" subevent, and it waits for 0.1 seconds (I'm guessing that's enough for some frames of the animation that was already playing to play out), it starts playing the animation again and only then enters the stop event.
B
6
S
2
Posts: 79
Reputation: 608

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Cub3D, David181, yiuyiu6666 and 27 guests