AnimationFinish in script editor?

Non-platform specific questions.

AnimationFinish in script editor?

Postby supatails » Wed Aug 22, 2012 8:24 pm

I'm using the state method to try and add an ability the character can achieve later on in the game. Things are getting complicated for me and I'm having trouble wrapping my mind around what's happening. :shock:
Code: Select all
switch(state)
{
    case 0: //if floober is standing facing right
    case 2: //or walking to the right
    ChangeAnimation("Event Actor", "floober_squish_right1", FORWARD); //play the squishing animation
    //here I want the code: upon animationfinish, changeanimation to flat floober,
    state=6; //and then change state to 6.
    break; //finish executing this block of code
}

BUT, I don't want you to have to hold the button down to stay flat, I want you to have to press the up key while you are squished to pop back up into the normal idle state.
with that in mind, should I still use the state integer for squishing, or should i create a new int for squish? I dunno, maybe I'm thinking about it too hard and overlooking the obvious, which I tend to do a lot while coding.
this is what i have for they keydown>up:
Code: Select all
switch(state)
{
    case 6: //if you are squished and you press the up key
    ChangeAnimation("Event Actor", "floober_shlop_right1", FORWARD); //play the animation of floober popping up off the ground and returning to his idle state.
    // here I want an animation finish code to tell floober to play the idle_right animation once finished with popping up off the ground.
    state=0; //return to the idle_right state.
    break;
}

any suggestions? :D
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Re: AnimationFinish in script editor?

Postby skydereign » Wed Aug 22, 2012 9:03 pm

You mentioned that you read that page I made on the wiki. In it I suggest making a value of state for every animation that your actor will have. The idea of the state variable is very simple. It holds the state (action) the actor is in. So you change it whenever the actor changes, and crouching/squishing sounds like a different state to me.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: AnimationFinish in script editor?

Postby supatails » Thu Aug 23, 2012 8:39 am

Sky, you have absolutely no idea how helpful
skydereign wrote:In it I suggest making a value of state for every animation that your actor will have.
was. XD Just by you suggesting a different state for each animation, which for whatever reason I hadn't picked up from the tutorial, I have been able to accomplish something I'm very proud of, I've figured out how to give floober powerups.
BUT:
I'm still experiencing a bug that, despite trying everything to the extent of my imagination withen the confines of if statements and switches, I can't get to the bottom of. The problem lies exactly with me being incapable of implementing AnimationFinish into the cases, there just isn't an AnimationFinish variable I can use. By using Animation Finish > Script Editor: etc. , a glitch occurs in which I am able to squish to the ground, and pop back up instantly without waiting for the corresponding "squish" and "pop back up" animations playing, just by pressing the movement keys before the animations have time to play. I've tried setting up statements like:
Code: Select all
if (animpos==5) ChangeAnimation( etc.
but it just doesn't work. I'd be so grateful if you could check out a demo and help me out with this problem, thanks.
Attachments
GubGurr.zip
(52.52 KiB) Downloaded 105 times
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Re: AnimationFinish in script editor?

Postby skydereign » Thu Aug 23, 2012 8:04 pm

You are still trying to use the squish variable. Why? By adding the squish states you can now use the variable state to determine if the player is being squished. Another thing is you are breaking the state animation correspondence. Whenever you change the player's animation, you change the player's state. In your animation finish events, you aren't changing state at all.

If you are using the state method as I outlined in the tutorial, you should use only one animation finish event (a script editor event). The switch(state) allows you to break up the actions into animations. case 0 would be the animation finish for stand right, case 1 would be the animation finish for stand left, and so on. Not all of them will have any code, but at least it is all in one place.

One other benefit to having states for every animation is that the game can distinguish between stand/move/squish/or anything else. It seems you already have states for the squish animation, so as long as you don't put the transition code for the squish state, it should work.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: AnimationFinish in script editor?

Postby supatails » Fri Aug 24, 2012 2:43 am

Oh the reason for the squish variable is to determine if floober has the ability to go into the squish states. As you can see from the demo, when floober collects the powerup (that ball on top of the pole), he is able to squish, because collision with the powerup sets squish to 1 and then destroys the powerup. Anyway thanks though, that really helped, and you solved my problem with the animations.
Now I've run into another problem:
1. I need to restrict the ability to pop out of the squish states if there is no room. At the moment you can slide under the small gap, but you are able to pop back up while underneath it and glitch on top of the platform. I'm stuck on how to get around this problem.
2. Occasionally but not always, when you go in and out of the squish states, especially while in motion, the "squish" and "shlop" animations play extra frames or something, making it look buggy and jerky. Is there a way around the weird, somewhat rare occurance?

here's a demo to explain my problems, and incase you didn't already know, left and right keys move, space is to jump, and once you collect the powerup, the down and up key get you in and out of "squish". And thanks for all of your help, you've really helped me grasp the concepts of game-editor and C++ so far. :D
Attachments
GubGurr.zip
(30.26 KiB) Downloaded 100 times
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Re: AnimationFinish in script editor?

Postby skydereign » Fri Aug 24, 2012 6:49 am

supatails wrote:Oh the reason for the squish variable is to determine if floober has the ability to go into the squish states. As you can see from the demo, when floober collects the powerup (that ball on top of the pole), he is able to squish, because collision with the powerup sets squish to 1 and then destroys the powerup

Ah, well I didn't actually look at your game. I just looked at bits of the player's code that seemed relevant. Looking at it now though, here is a tip.

This is what you have.
Code: Select all
DestroyActor("cheat_squish1");
squish=1;

That will destroy all cheat_squish1 actors. To test this, just create two of them close to each other. Bump into one of them, and both of them will be destroyed. That is because that code is telling you to destroy the cheat_squish1 actor (of which there are two). What you want to tell gE is to destroy the actor you are colliding with. Instead of "cheat_squish1" you can use "Collide Actor" to specify just the actor you are colliding with (this is similar to specifying "Event Actor").

Another thing I forgot to mention is you are using if statements incorrectly. You have in your keydown down event a chunk of code that looks similar to this.
Code: Select all
if(squish==1)
ChangeAnimation(...);
state=6;
if(squish==0)
state=0;

There are two things wrong with that. The first is you need brackets when using an if statement that has more than one action.
Code: Select all
// for example
if(state==0)
state=2;
state=3;

This no matter what state is equal to will change state to 3. This is because the if statement only applies to the one action after (setting state equal to 2). So even if state isn't equal to 0, state will be set equal to 3. To fix this use {} when dealing with if statements. Also, do you know about else if?
Code: Select all
if(state==0)
{
    state=2; // now it is obvious (and correct) that both of these are bound by the if
    state=3;
}

In your code though it is kind of fixed, because state will be set equal to 6 no matter what, but it will be set to 0 if squish is equal to 0.

The other thing about your code is you shouldn't change state without changing the animation. If you are running (state equal to 2), and you press down, your player will continue having the run animation, but its state will be set to 0. Again this doesn't cause any bugs in your game due to some lucky other part "fixing" the mistake. But you should avoid relying on accidental fixes.

supatails wrote:1. I need to restrict the ability to pop out of the squish states if there is no room. At the moment you can slide under the small gap, but you are able to pop back up while underneath it and glitch on top of the platform. I'm stuck on how to get around this problem.

This can be rather weird to fix. One way is to use the CollisionFree method. This will work if you don't have any other actors with enabled collision states that could get in the way. This is the method though that would make the most sense. Since you are learning gE I recommend you look up CollisionFree on this page. http://game-editor.com/docs/script_reference.htm
It helps to get in the habit of looking things up on that page. If you still need help with implementing it, I can provide more detail on it.

supatails wrote:2. Occasionally but not always, when you go in and out of the squish states, especially while in motion, the "squish" and "shlop" animations play extra frames or something, making it look buggy and jerky. Is there a way around the weird, somewhat rare occurance?

Try changing the FORWARD to NO_CHANGE in the ChangeAnimation function calls.

One other thing I thought I should mention. In global code you have a bunch of one line scripts declaring different variables. They don't have to each have their own script. You could make a single one with all the variables there.
Code: Select all
int state;
int squish;
int evo;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: AnimationFinish in script editor?

Postby supatails » Mon Aug 27, 2012 6:52 am

I followed your advice and things are working great now! The CollisionFree thing is awesome. Now I'm having trouble with a certain concept. I've started coding for a new floober ability:
By default, squish=0. By different means, in this scenario by a powerup, squish is set to 1, which allows you to squish down to about 1/3 of your size, and slide around under tight spaces. Now I have created a new powerup which will set squish to 2. While in squish mode, floober now has the capability to slide up walls. Here's the delima though:
I'm able to use collision events to change floobers animation state and gravity state so he can slide up and down the wall at acute angles, but the problem comes in at obtuse angles. I have no way to tell floober when to bend around the corner because there's nothing to collide with.
Image
Now I could simply create an invisible box, and upon collision with that change the state, but I'd consider that cheating in my mind, I wanna have the abilities to be more natural so I don't have to place invisible collision boxes everywhere, this way floober could easily traverse even randomly generated worlds. Also, somewhat relating to the same issue, I want to prevent floober from being able to slide off of a ledge while squished down in order to avoid collision problems with falling at that speed.
I'm really stumped on this one. Also, if you jump while your on a wall, you will pop off of the wall a few feet. Any ideas? XD Sorry I keep making my requests more and more complex, but you always explain stuff in a way I'm able to learn from.
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron