Page 1 of 1

thoughts about state methods

PostPosted: Wed Oct 30, 2013 9:16 pm
by sonicforvergame
I have realized that state method is quite essential to simplify text and create scripts that allow various important actions
Ge provide a tutorial on the game editor website and explain how to do movement and jumping with state method
i was able to understand how to use state method but i still didn't figure out hot to create other action similar to jumping wit state method
for example:
i want my character crouching to the left if standing left and right if standing right,now i used the same code as the one i used for jumping but i didn't really work because i didn't know which state or case does crouching refer

So to sum up
i would like to know how to add more animation by using state and now which value i should enter so GE work properly

Re: thoughts about state methods

PostPosted: Wed Oct 30, 2013 9:35 pm
by skydereign
The value of the states does not matter, as long as they are unique. Your stand state could be represented by a value 0, 99, or 12994. What makes the state method work is that in each input that would change the actor's state, you use a switch statement so you can outline the exact transition code you want. So in your crouch keydown event, you need to decide which states transition to what.

player -> Key Down down (repeat enabled)
  • stand right transitions to crouch right
  • stand left transitions to crouch left

You also need to define ways to transition out of the new states, otherwise no input event would be able to escape the new state and your actor will freeze.
player -> Key Up down
  • crouch right transitions to stand right
  • crouch left transitions to stand left

In general a transition only requires two lines of code. One to change the value of state to the corresponding state, and two to change the animation to the proper state. Here's the script for the key down event.
Code: Select all
switch(state)
{
    case 0: // stand right
    ChangeAnimation("Event Actor", "crouch_right", FORWARD);
    state = 4; // assuming crouch right is represented by 4
    break;

    case 1: // case for stand left transitioning to crouch left
    ChangeAnimation("Event Actor", "crouch_left", FORWARD);
    state = 5;
    break;
}


To sum it up, to add a new state you need to pick a value for that state, and provide transition code to and from it. Transitions require minimally the change of the state value, but usually also include a ChangeAnimation call.

Re: thoughts about state methods

PostPosted: Thu Oct 31, 2013 4:37 am
by sonicforvergame
thanks skyderign that was awsome
and by the way
can ge use mathematical expression like this

Code: Select all
if sonic touch enemie and ringcount=<20
create half of ringcount
if ringcount=>50
create one third of ringcount

Re: thoughts about state methods

PostPosted: Thu Oct 31, 2013 5:00 am
by skydereign
sonicforvergame wrote:thanks skyderign that was awsome
and by the way
can ge use mathematical expression like this

Code: Select all
if sonic touch enemie and ringcount=<20
create half of ringcount
if ringcount=>50
create one third of ringcount

Yes, C can compare values.
Code: Select all
if(x>=0) {}
if(x<=0) {}
if(x>0) {}
if(x<0) {}
if(x==0) {}

Re: thoughts about state methods

PostPosted: Thu Oct 31, 2013 4:03 pm
by sonicforvergame
thank you :D