thoughts about state methods

Game Editor comments and discussion.

thoughts about state methods

Postby sonicforvergame » Wed Oct 30, 2013 9:16 pm

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
Kaizoku ni ore wa naru
User avatar
sonicforvergame
 
Posts: 422
Joined: Sat Sep 01, 2012 2:17 pm
Score: 10 Give a positive score

Re: thoughts about state methods

Postby skydereign » Wed Oct 30, 2013 9:35 pm

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

Re: thoughts about state methods

Postby sonicforvergame » Thu Oct 31, 2013 4:37 am

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
Kaizoku ni ore wa naru
User avatar
sonicforvergame
 
Posts: 422
Joined: Sat Sep 01, 2012 2:17 pm
Score: 10 Give a positive score

Re: thoughts about state methods

Postby skydereign » Thu Oct 31, 2013 5:00 am

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

Re: thoughts about state methods

Postby sonicforvergame » Thu Oct 31, 2013 4:03 pm

thank you :D
Kaizoku ni ore wa naru
User avatar
sonicforvergame
 
Posts: 422
Joined: Sat Sep 01, 2012 2:17 pm
Score: 10 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest