Page 6 of 7

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Thu May 29, 2014 5:15 pm
by Turon
When I jump and then shoot the player's animation will change to a standing posture as apposed to a jump posture, Now I'd imagine that making jumping part of the system would be more complicated due to the fact that shooting is handled with a different variable.

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Thu May 29, 2014 8:10 pm
by Hares
After the shooting your animation changes to the standing position because of what you coded in the z key up event.

This is what you have there now:
Code: Select all
if(shootdir==1)ChangeAnimation("Event Actor", "PlayerStillLeft", NO_CHANGE);
if(shootdir==2)ChangeAnimation("Event Actor", "PlayerStillRight", NO_CHANGE);


If you change it to somehting like this it should work the way you want it to:
Code: Select all
if(shootdir==1) //shooting to the left
{
    if (playerdir==5) //when jumping facing left
    {
        ChangeAnimation("Event Actor", "PlayerJumpLeft", FORWARD);
    }
    else
    {
        ChangeAnimation("Event Actor", "PlayerStillLeft", NO_CHANGE);
    }
}

if(shootdir==2) //shooting to the right
{
    if (playerdir==4) //when jumping facing right
    {
        ChangeAnimation("Event Actor", "PlayerJumpRight", FORWARD);
    }
    else
    {
        ChangeAnimation("Event Actor", "PlayerStillRight", NO_CHANGE);
    }
}

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Mon Jun 02, 2014 10:36 am
by Turon
Yes the code works when you are jumping without holding down a left or right key but when you do the shoot animation will not play and it will stay in a jump animation.
And also... is it possible to use state method when talking about multiple variables?

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Mon Jun 02, 2014 11:15 am
by lcl
One thing I'd like to ask you, is why to use an extra variable for shooting? You can just have one more state for your actor.

Also, I'd suggest using #define to make the managing of multiple different states easier.
#define allows you to define a word and tell what the compiler should treat that word as.

#define statements should be written in to Global.

Here's an example. Write this to Global Code and add the code with a name:
Code: Select all
#define STAND_RIGHT 0
#define STAND_LEFT 1

Now, when ever you'd like to use your states for standing right or standing left, instead of the numbers 0 and 1, you can write STAND_RIGHT or STAND_LEFT.
Like this:
Code: Select all
switch(state)
{
    case STAND_RIGHT:
        //Do something here
    break;

    case STAND_LEFT:
        //Do something here, too
    break;
}

How the compiler will see the above code:
Code: Select all
switch(state)
{
    case 0:
        //Do something here
    break;

    case 1:
        //Do something here, too
    break;
}

So, define allows you to stay more organized with your states without causing any difference to how the compiler sees your code.
You can also use the defined words to set your state variable to a certain value:
Code: Select all
state = STAND_RIGHT;







There's also a lot things #define can do, since you can use it to define anything to anything, you can even do this:
Code: Select all
#define KILL DestroyActor("Event Actor") //No semicolon here!

And then, for example, in key down -> enter:
Code: Select all
KILL;

That will destroy the event actor. :D
So, defines can be really useful, especially with what you're doing with the state method.

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Mon Jun 02, 2014 11:53 am
by Turon
So I don't need two variables?

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Mon Jun 02, 2014 12:43 pm
by lcl
Turon wrote:So I don't need two variables?

No, why would you? Just use a new state value for the cases of shooting left and shooting right.

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Mon Jun 02, 2014 3:54 pm
by Turon
I'll try what you said when I've got my computer running.

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Thu Jun 05, 2014 9:03 am
by Turon
Why is that variable called "state" instead of a more meaningful name?

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Thu Jun 05, 2014 10:17 am
by skydereign
Turon wrote:Why is that variable called "state" instead of a more meaningful name?

state is almost the most meaningful name for the variable. The only thing that would be more meaningful is player_state or similar, but at that point it is not generic to all actors, and it is longer to type. States are a well defined concept and fit the description perfectly.
Google Definition wrote:State
1. the particular condition that someone or something is in at a specific time

The state method also is an implementation of a state machine, something very well defined in computer science. States in a state machine are meant to be identical to the states in the state method. The variable holds which state the actor is in. What more meaningful name would you suggest?

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Thu Jun 05, 2014 10:54 am
by Turon
Um Lcl I've been trying out this idea and I changed some of the values but it seems I've created a mess. the code looks exactly the same as what it did just with this idea.

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Mon Jun 09, 2014 6:14 am
by Turon
Something wrong with the values?

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Mon Jun 09, 2014 10:06 am
by lcl
If you're using the #defines you should then only use them. If you use the #defines to check what the state is, you should also use them to set the states. If you use your state variable via #defines and plain numbers, you're going to get confused.

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Mon Jun 09, 2014 10:37 am
by foleyjo
When applying numbers to a word is it best to use #defines or enums?

Reason I ask is because i've used enums for something similar

ie

enum PlayerStates = {Walking = 0, jumping = 1, dying = 2, etc..};

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Mon Jun 09, 2014 10:48 am
by lcl
Well, there isn't much of a difference between using these two, but #defines can be used with all integers or whatever type of variable has been assigned to them. Enums can only be used with enums of the same type. I usually use #defines, but enums can be handy if you need a list of variables assigned to words that you want only to be usable by a certain type of variable. To me, #define just seems simpler and more understandable than enums, but that's mostly because I've never used enums.

Re: Setting Animation for Actor(Experimenting with State Met

PostPosted: Mon Jun 09, 2014 3:56 pm
by skydereign
foleyjo wrote:When applying numbers to a word is it best to use #defines or enums?

In gE you won't really see a difference. In this case though enums are actually a slightly better way to do it, since you can add states and never have to worry about their values.