Design Designing a State Machine for your Game

G

gamedev4life

Guest
Hi all! Learning how to make a state machine was a turning point for me in learning how to programming a game in GML, so I wanted to help others learn how to make a state machine which is the purpose of this post :)

I know there's more than one way to make a state machine, but this is my favorite way to do it (see youtube video below). All feedback is very much appreciated and will help me make better GML tutorials. Thanks!

 
V

Vincent

Guest
Yes, I've been making a game recently and that kind of state machine makes things a looot easier :D
 

Yal

šŸ§ *penguin noises*
GMC Elder
My favorite way of doing state machines?
Code:
script_execute(state)
Not optimal for throwaway enemies and effect objects, but really handy with complex stuff like player characters and bosses. It's more of an infinite-state machine since you can change to ANY script, but it can be really handy with those since you often need to insert completely new states... ESPECIALLY for the player.

The second-easiest approach? I'd say it's something like this:
Code:
switch(state){
  case 0://Do something
    approach_player_menacingly();
    if(close_enough){state = 1}
  break

  case 1://Do something else
    attack_player()
  break
}
 
Top