Page 1 of 1

Need Help Using State Variable

PostPosted: Mon Aug 30, 2010 3:31 am
by SuperNoob
So here's my problem: I have six animations, though there will be plenty more after I get this initial issue sorted out, and I am using a "state" variable to manage my character's animations, and so far, I have been successful at using the switch statement to regulate between standing and walking left and right, which occupies cases 0-3, but for some reason, no matter what I try, I can't get the down key to register my ducking animation, even though the code says it should be working, as far as I can tell, and for some reason, in a few of the combinations I have tried, the down key has reacted only if I was holding the left or right key at the same time, and I can't figure out why.

To make things worse, I would like to eventually implement a fluid turning and ducking animation to transition between states, but I have no idea how I will make that work when I can't even get the switch statement to recognize the variables properly, or my down key to even register my duck animation.

Any ideas why this might be happening, or suggestions for better ways to manage complex movement?

Re: Need Help Using State Variable

PostPosted: Mon Aug 30, 2010 6:11 am
by skydereign
Well the down key switch statement should look just like that of the key right/left. The only significant difference is the animation name and which states are being activated. The down key switch should have cases for 0-3, all setting to the proper ducking animation.

I assume this is your state structure.
0 = stand right
1 = stand left
2 = move right
3 = move left

If that is the case then you will also need state values for ducking right/left, as well as any transitions. You can get by without the transitions having their own state variables if you don't mind them being interrupted easily. If that is the case then just make sure to have animation finish events for the transitional animations accurate to the state. The problem with that is the state variable should always accurately tell you what the actor is doing, and what animation it has, like animindex.

I can't do much without knowing more of your setup, can you post the ged and data files? That or put all the script's .c files into a zip and upload that.

Have you seen this? It has an example of the state method in it, and seems to contain all the base states that you want.
http://game-editor.com/Moonwalking

Re: Need Help Using State Variable

PostPosted: Fri Sep 03, 2010 1:28 am
by SuperNoob
Thanks for your help, but I already figured out what I was doing wrong, and everything is working fine. Now I'm trying to figure out a way for my character to stand up when the shooting while ducking animation finishes and the down key is released before the animation is finished, because as it exists now I have a single file for the down state, with a ducking animation to transition between that and the standing state, and when the shooting while ducking state finishes, it gets stuck on the single ducked animation, unless I press the down key again and the key up event tells the character to stand.

Do you know of an if statement I can use to determine if the key is still held down when the animation finishes to determine whether it should stay in the ducked position, or switch to the standing animation? I've been reading about how to use GetKeyState, but it only seems to work in a draw actor event, and I am using an animation finish event for when the shooting while ducking animation finishes. Complex stuff. Any ideas?

Re: Need Help Using State Variable

PostPosted: Fri Sep 03, 2010 1:35 am
by skydereign
GetKeyState works on any event. The following code should change the actor's color upon the event.

Code: Select all
char * key = GetKeyState();
if(key[KEY_DOWN]==1)
{
    r=0;
}

Re: Need Help Using State Variable

PostPosted: Fri Sep 03, 2010 1:47 am
by SuperNoob
Fabulous. Thanks again.