Setting Animation for Actor(Experimenting with State Method)

Non-platform specific questions.

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Thu May 29, 2014 5:15 pm

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.
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Hares » Thu May 29, 2014 8:10 pm

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);
    }
}
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Mon Jun 02, 2014 10:36 am

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?
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby lcl » Mon Jun 02, 2014 11:15 am

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.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Mon Jun 02, 2014 11:53 am

So I don't need two variables?
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby lcl » Mon Jun 02, 2014 12:43 pm

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.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Mon Jun 02, 2014 3:54 pm

I'll try what you said when I've got my computer running.
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Thu Jun 05, 2014 9:03 am

Why is that variable called "state" instead of a more meaningful name?
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby skydereign » Thu Jun 05, 2014 10:17 am

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?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Thu Jun 05, 2014 10:54 am

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.
Attachments
Statik's World.zip
(14.88 KiB) Downloaded 184 times
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby Turon » Mon Jun 09, 2014 6:14 am

Something wrong with the values?
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby lcl » Mon Jun 09, 2014 10:06 am

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.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby foleyjo » Mon Jun 09, 2014 10:37 am

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..};
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby lcl » Mon Jun 09, 2014 10:48 am

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.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Setting Animation for Actor(Experimenting with State Met

Postby skydereign » Mon Jun 09, 2014 3:56 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron