Page 1 of 7

Setting Animation for Actor(Experimenting with State Method)

PostPosted: Sun Feb 16, 2014 8:47 am
by Turon
Hi all

This time I'm not trying to Accelerate, I would like to allow the players animation to have a Right & Left Jump animation & a Right & Left Shoot Animation. I thought that I could perhaps get the desired results by modifying some of the code from the last topic, However Game Editor can't except my code and I dont know quite whats wrong with it.

Code: Select all
char* key = GetKeyState();
if (key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 0)
{
   // IF KEY RIGHT IS PRESSED AND NOT LEFT
   if(key[KEY_x]==1 && key[KEY_z]==1) (
      // AND THEN IF X IS ALSO PRESSED
     ChangeAnimation("Event Actor", "PlayerJumpRight", NO_CHANGE);
    }
    else
    {   
           //IF Z IS PRESSED AND NOT X
           ChangeAnimation("Event Actor", "PlayerShootRight", NO_CHANGE);
   }
   else
   {
       // BUT IF X ISN'T PRESSED
      x+=3;
      ChangeAnimation("Event Actor", "PlayerMoveRight", NO_CHANGE);
}

if (key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
   // IF KEY LEFT IS PRESSED AND NOT RIGHT
   if(key[KEY_x]==1 && key[KEY_z]==1) (
     // AND THEN IF X IS ALSO PRESSED
      ChangeAnimation("Event Actor", "PlayerJumpLeft", NO_CHANGE);
    }
    else
    {
       // IF Z IS PRESSED AND X
       ChangeAnimation("Event Actor", "PlayerShootLeft", NO_CHANGE);
    }
    else
    { 
   // BUT IF X ISN'T PRESSED
       x-=3;
       ChangeAnimation("Event Actor", "PlayerMoveLeft", NO_CHANGE);
    }
}   

-EDIT-
all of the earlier posts in this topic are irreverent to the current issue, please search the latest posts.

Re: Game Editor Favors Right over Left Continuation

PostPosted: Sun Feb 16, 2014 10:03 am
by tvz
char* key = GetKeyState();
if (key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 0)
{
// IF KEY RIGHT IS PRESSED AND NOT LEFT
if(key[KEY_x]==1 && key[KEY_z]==1) ( <--------------------------------------this bracket
// AND THEN IF X IS ALSO PRESSED
ChangeAnimation("Event Actor", "PlayerJumpRight", NO_CHANGE);
}
else
{
//IF Z IS PRESSED AND NOT X
ChangeAnimation("Event Actor", "PlayerShootRight", NO_CHANGE);
}
else
{
// BUT IF X ISN'T PRESSED
x+=3;
ChangeAnimation("Event Actor", "PlayerMoveRight", NO_CHANGE);
}

if (key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
// IF KEY LEFT IS PRESSED AND NOT RIGHT
if(key[KEY_x]==1 && key[KEY_z]==1) (<--------------------------------------this bracket
// AND THEN IF X IS ALSO PRESSED
ChangeAnimation("Event Actor", "PlayerJumpLeft", NO_CHANGE);
}
else
{
// IF Z IS PRESSED AND X
ChangeAnimation("Event Actor", "PlayerShootLeft", NO_CHANGE);
}
else
{
// BUT IF X ISN'T PRESSED
x-=3;
ChangeAnimation("Event Actor", "PlayerMoveLeft", NO_CHANGE);
}
}

Re: Game Editor Favors Right over Left Continuation

PostPosted: Sun Feb 16, 2014 6:22 pm
by Turon
Do I have to change my codes spacing as shown in your code? I removed those "(" and ")" that you seemed to be telling me to remove, but GE will still not except my code :?.......

Re: Game Editor Favors Right over Left Continuation

PostPosted: Sun Feb 16, 2014 7:44 pm
by Hares
To get the code accepted I changed it like this:
Code: Select all
char* key = GetKeyState();
if (key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 0)
{
    // IF KEY RIGHT IS PRESSED AND NOT LEFT
    if(key[KEY_x]==1)
        // AND THEN IF X IS ALSO PRESSED
    {
        ChangeAnimation("Event Actor", "PlayerJumpRight", NO_CHANGE);
    }
    if (key[KEY_z]==1 && key[KEY_x]!=1)
    {
        //IF Z IS PRESSED AND NOT X
        ChangeAnimation("Event Actor", "PlayerShootRight", NO_CHANGE);
    }
    if (key[KEY_x]!=1)
    {
        // BUT IF X ISN'T PRESSED
        x+=3;
        ChangeAnimation("Event Actor", "PlayerMoveRight", NO_CHANGE);
    }
}

if (key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
    // IF KEY LEFT IS PRESSED AND NOT RIGHT
    if(key[KEY_x]==1 && key[KEY_z]==1)
    {
       // AND THEN IF X IS ALSO PRESSED
       ChangeAnimation("Event Actor", "PlayerJumpLeft", NO_CHANGE);
    }
    if (key[KEY_z]==1 && key[KEY_x]==1)
    {
        // IF Z IS PRESSED AND X
        ChangeAnimation("Event Actor", "PlayerShootLeft", NO_CHANGE);
    }
    if (key[KEY_x]!=1)
    {
        // BUT IF X ISN'T PRESSED
        x-=3;
        ChangeAnimation("Event Actor", "PlayerMoveLeft", NO_CHANGE);
    }
}


What you did was: have an if statement, and after that 2 else statments. I think that that is the reason why you got the errors.
So I changed it into three if statements, and now it gets accepeted.

Maybe it is supposed to be like this in your game, but on the right key down check (first chunk of code) you check if z is pressed and not x.
And on the left key down check (second chunk of code) you check if z and x are both pressed.

Anyway, I hope it works for you now :)

Re: Game Editor Favors Right over Left Continuation

PostPosted: Mon Feb 17, 2014 12:26 pm
by tvz
i mean you should change the " ( " bracket at the last of those statement with " { " this bracket
and hares said it correct, the other problem was using 2 'else' with 1 'if'

Re: Game Editor Favors Right over Left Continuation

PostPosted: Wed Feb 19, 2014 11:08 am
by Turon
Sorry to confuse you but my code had a typo so I typed "IF Z IS PRESSED AND X" which was meant to be "IF Z IS PRESSED AND NOT X"

tvz I've add those "{" things like you told me but the code has not been excepted. What do you mean by 2 else and 1 if?

Re: Game Editor Favors Right over Left Continuation

PostPosted: Thu Feb 20, 2014 8:29 pm
by Hares
Turon wrote:What do you mean by 2 else and 1 if?

Your code is like this:
if (check some thing)
{
do some thing;
}
else
{
do some thing else;
}
else
{
do some thing else (again :?: );
}

}

It is the red part that makes your code unacceptable.

Turon wrote:Sorry to confuse you but my code had a typo so I typed "IF Z IS PRESSED AND X" which was meant to be "IF Z IS PRESSED AND NOT X"

I modified that in the code below.
So I suggest you copy the code below here (push the select all button)
Then in your .ged you erase your code, and replace it by the one you copied.
See if it gets accepted.
If (so)
{
figure out what is different from your code, and try to understand it;
}
else
{
report back here;
and we try to help you figure it out;
}
else
{
forget about the second else ...
}

}
:)


Code: Select all
char* key = GetKeyState();
if (key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 0)
{
    // IF KEY RIGHT IS PRESSED AND NOT LEFT
    if(key[KEY_x]==1)
    // AND THEN IF X IS ALSO PRESSED
    {
        ChangeAnimation("Event Actor", "PlayerJumpRight", NO_CHANGE);
    }
    if (key[KEY_z]==1 && key[KEY_x]!=1)
    {
        //IF Z IS PRESSED AND NOT X
        ChangeAnimation("Event Actor", "PlayerShootRight", NO_CHANGE);
    }
    if (key[KEY_x]!=1)
    {
        // BUT IF X ISN'T PRESSED
        x+=3;
        ChangeAnimation("Event Actor", "PlayerMoveRight", NO_CHANGE);
    }
}

if (key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
    // IF KEY LEFT IS PRESSED AND NOT RIGHT
    if(key[KEY_x]==1 && key[KEY_z]==1)
    {
       // AND THEN IF X IS ALSO PRESSED
       ChangeAnimation("Event Actor", "PlayerJumpLeft", NO_CHANGE);
    }
    if (key[KEY_z]==1 && key[KEY_x]!=1)
    {
        // IF Z IS PRESSED AND NOT X
        ChangeAnimation("Event Actor", "PlayerShootLeft", NO_CHANGE);
    }
    if (key[KEY_x]!=1)
    {
        // BUT IF X ISN'T PRESSED
        x-=3;
        ChangeAnimation("Event Actor", "PlayerMoveLeft", NO_CHANGE);
    }
 }

Re: Game Editor Favors Right over Left Continuation

PostPosted: Thu Feb 20, 2014 10:04 pm
by lcl
Hares wrote:Then in your .ged you erase your code, and replace it by the one you copied.
See if it gets accepted.
If (so)
{
figure out what is different from your code, and try to understand it;
}
else
{
report back here;
and we try to help you figure it out;
}
else
{
forget about the second else ...
}

}
:)

Gotta love that post! :mrgreen: :lol:

Re: Game Editor Favors Right over Left Continuation

PostPosted: Fri Feb 21, 2014 9:09 am
by Turon
Let me just make sure that you understand what I'm trying to do, the code was accepted however, x is for jumping and z is for shooting, my shooting animations play out but not my jumping and walking (moving) animation.

Re: Game Editor Favors Right over Left Continuation

PostPosted: Fri Feb 21, 2014 3:43 pm
by tvz
Hares wrote:
Turon wrote:What do you mean by 2 else and 1 if?


If (so)
{
figure out what is different from your code, and try to understand it;
}
else
{
report back here;
and we try to help you figure it out;
}
else
{
forget about the second else ...
}

}
:)





Unique post ever. :lol:

Hares :
there are two 'else' statements under the 'if' condition. you cant use 'more that 1' else statement under 'if'

Re: Game Editor Favors Right over Left Continuation

PostPosted: Fri Feb 21, 2014 4:55 pm
by Hares
Turon wrote:the code was accepted

That is good news :D
Turon wrote:my shooting animations play out but not my jumping and walking (moving) animation.

That is not so good news
In the code below I changed it so that when the x is pressed, it also checks if the z is not pressed.
And to change to the walking animation it checks if both the x and z are not pressed.

Code: Select all
char* key = GetKeyState();
if (key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 0)
{
    // IF KEY RIGHT IS PRESSED AND NOT LEFT
    if(key[KEY_x]==1 && key[KEY_z]!=1)
    // AND THEN IF X IS ALSO PRESSED AND Z IS NOT PRESSED
    {
            ChangeAnimation("Event Actor", "PlayerJumpRight", NO_CHANGE);
    }
    if (key[KEY_z]==1 && key[KEY_x]!=1)
    {
        //IF Z IS PRESSED AND NOT X
        ChangeAnimation("Event Actor", "PlayerShootRight", NO_CHANGE);
    }
    if (key[KEY_x]!=1 && key[KEY_z]!=1)
    {
        // BUT IF X ISN'T PRESSED AND Z IS NOT PRESSED
        x+=3;
        ChangeAnimation("Event Actor", "PlayerMoveRight", NO_CHANGE);
    }
}

if (key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
   // IF KEY LEFT IS PRESSED AND NOT RIGHT
    if(key[KEY_x]==1 && key[KEY_z]!=1)
    {
       // AND THEN IF X IS ALSO PRESSED AND NOT Z
       ChangeAnimation("Event Actor", "PlayerJumpLeft", NO_CHANGE);
   }
   if (key[KEY_z]==1 && key[KEY_x]!=1)
   {
       // IF Z IS PRESSED AND NOT X
        ChangeAnimation("Event Actor", "PlayerShootLeft", NO_CHANGE);
    }
    if (key[KEY_x]!=1 && key[KEY_z]!=1)
    {
        // BUT IF X ISN'T PRESSED AND Z IS NOT PRESSED
        x-=3;
        ChangeAnimation("Event Actor", "PlayerMoveLeft", NO_CHANGE);
    }
 }

I think it should work the way you intend it now.
If not I suspect the error is not in this code, but somewhere else.
But to figure that out I would need to see the .ged file.

lcl wrote:Gotta love that post! :mrgreen: :lol:

tvz wrote:Unique post ever. :lol:

Yeah, my first coding humor ever :mrgreen:

Re: Game Editor Favors Right over Left Continuation

PostPosted: Fri Feb 21, 2014 6:15 pm
by Turon
Sorry Hares but your latest code has the same resolts as last time, I don't know will this ged. here will help at all?

Re: Game Editor Favors Right over Left Continuation

PostPosted: Fri Feb 21, 2014 7:26 pm
by Hares
The code I modified for you should go in the "draw actor"event of the player.
In your game you put it in the "key down" event for left or right arrow.

When I copied the code the draw actor event, it still didn't do what you expect it to do.
Because in your initial code you made it that the jump and shoot animations only happen when the left or right arrow is held down.

The reason why your shooting animation was working, was because you also set in in the "key down" event of the z key.

This is the code as I think you want it, to put in the "draw actor":
Code: Select all
char* key = GetKeyState();
if(key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 0)
// IF KEY RIGHT IS PRESSED AND NOT LEFT
{
    dir=2;
    x+=3;
    if(key[KEY_x]!=1 && key[KEY_z]!=1 && jump==1)
    //IF X ISN'T PRESSED AND Z IS NOT PRESSED AND PLAYER IS NOT JUMPING
    {
        ChangeAnimation("Event Actor", "PlayerMoveRight", NO_CHANGE);
    }
}
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
// IF KEY LEFT IS PRESSED AND NOT RIGHT
{
    dir=1;
    x-=3;
    if(key[KEY_x]!=1 && key[KEY_z]!=1 && jump==1)
    // BUT IF X ISN'T PRESSED AND Z IS NOT PRESSED AND PLAYER IS NOT JUMPING
    {
        ChangeAnimation("Event Actor", "PlayerMoveLeft", NO_CHANGE);
    }
}

if (dir==2)
//IF LOOKING TO THE RIGHT
{
    if(key[KEY_x]==1 && key[KEY_z]!=1)
    // AND THEN IF X IS ALSO PRESSED AND Z IS NOT PRESSED
    {
        ChangeAnimation("Event Actor", "PlayerJumpRight", NO_CHANGE);
    }
    if(key[KEY_z]==1 && key[KEY_x]!=1)
    {
        //IF Z IS PRESSED AND NOT X
        ChangeAnimation("Event Actor", "PlayerShootRight", NO_CHANGE);
    }
}

if (dir==1)
//IF LOOKING TO THE LEFT
{
    if(key[KEY_x]==1 && key[KEY_z]!=1)
    // AND THEN IF X IS ALSO PRESSED AND NOT Z
    {
        ChangeAnimation("Event Actor", "PlayerJumpLeft", NO_CHANGE);
    }
    if(key[KEY_z]==1 && key[KEY_x]!=1)
    // IF Z IS PRESSED AND NOT X
    {
        ChangeAnimation("Event Actor", "PlayerShootLeft", NO_CHANGE);
    }
}

yvelocity++;


Then I removed the "key down" events for:
-left and right
-right
-left

And in the "key down" for z I removed the changeAnimation functions for the player.

Here is the modified .ged:

Re: Game Editor Favors Right over Left Continuation

PostPosted: Mon Feb 24, 2014 7:20 am
by Turon
Thanks a Billion Hares! Works Beutifuly and once again I was helped out by a newbie :lol: !

Re: Game Editor Favors Right over Left Continuation

PostPosted: Mon Feb 24, 2014 8:46 pm
by Hares
You're welcome dude.

Do you understand the changes, and do you understand why it works now?