Setting Animation for Actor(Experimenting with State Method)

Non-platform specific questions.

Setting Animation for Actor(Experimenting with State Method)

Postby Turon » Sun Feb 16, 2014 8:47 am

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.
Attachments
Game Editor Favors Right Over Left.png
Last edited by Turon on Mon May 26, 2014 1:08 pm, edited 6 times in total.
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Game Editor Favors Right over Left Continuation

Postby tvz » Sun Feb 16, 2014 10:03 am

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);
}
}
User avatar
tvz
 
Posts: 98
Joined: Sun Mar 10, 2013 7:13 am
Location: Your PC screen
Score: 3 Give a positive score

Re: Game Editor Favors Right over Left Continuation

Postby Turon » Sun Feb 16, 2014 6:22 pm

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

Re: Game Editor Favors Right over Left Continuation

Postby Hares » Sun Feb 16, 2014 7:44 pm

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

Re: Game Editor Favors Right over Left Continuation

Postby tvz » Mon Feb 17, 2014 12:26 pm

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'
User avatar
tvz
 
Posts: 98
Joined: Sun Mar 10, 2013 7:13 am
Location: Your PC screen
Score: 3 Give a positive score

Re: Game Editor Favors Right over Left Continuation

Postby Turon » Wed Feb 19, 2014 11:08 am

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

Re: Game Editor Favors Right over Left Continuation

Postby Hares » Thu Feb 20, 2014 8:29 pm

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

Re: Game Editor Favors Right over Left Continuation

Postby lcl » Thu Feb 20, 2014 10:04 pm

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

Re: Game Editor Favors Right over Left Continuation

Postby Turon » Fri Feb 21, 2014 9:09 am

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

Re: Game Editor Favors Right over Left Continuation

Postby tvz » Fri Feb 21, 2014 3:43 pm

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'
User avatar
tvz
 
Posts: 98
Joined: Sun Mar 10, 2013 7:13 am
Location: Your PC screen
Score: 3 Give a positive score

Re: Game Editor Favors Right over Left Continuation

Postby Hares » Fri Feb 21, 2014 4:55 pm

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

Re: Game Editor Favors Right over Left Continuation

Postby Turon » Fri Feb 21, 2014 6:15 pm

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?
Attachments
Game Editor Favors Right Over Left GED.zip
This is the Problem ged.
(26.1 KiB) Downloaded 761 times
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Game Editor Favors Right over Left Continuation

Postby Hares » Fri Feb 21, 2014 7:26 pm

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:
Attachments
Statik's World-Hares.ged
Here is the modified .ged file. Just put it in the same folder as the original, and open it with Game Editor
(7.88 KiB) Downloaded 792 times
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: Game Editor Favors Right over Left Continuation

Postby Turon » Mon Feb 24, 2014 7:20 am

Thanks a Billion Hares! Works Beutifuly and once again I was helped out by a newbie :lol: !
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Game Editor Favors Right over Left Continuation

Postby Hares » Mon Feb 24, 2014 8:46 pm

You're welcome dude.

Do you understand the changes, and do you understand why it works now?
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron