Finite State Machines

Finite State Machines

Rukiri – 6/5/17

What is a finite state machine? It’s a simple machine that checks for the current state, think of a loop.  If the current look is in repeat the state is repeat but if nothing is happening the state is idle.     But why would you want a state machine, why not code for specific objects?  We’ll the reason you want to use states is to actually break each and everything into snippets this makes the code more portable and reusable and also break your code down so if something is wrong you can than dig to the exact state to work on.

How is the state machine handled in Game Maker, Unity, or even Godot?  A state is simply that, a state.  You can make the machine as complex as you want, or make it as simple as you want, the end result would be the same.   So if you hold shift that probably means you're activating the dash state so somewhere in your update script you have a check for each state to activate.   

A basic state machine will look like this in Game Maker.

// Create Event

scr_player_states(); // example enum state { idle, move, running }

// Step Event

Switch (state) {

case state.idle: scr_player_idle(); break;

case state.move: scr_player_move(); break;

case state.running: scr_player_running(); break;


// scr_player_states

enum state {





So each state will have it’s own script, this is actually very useful if you’re doing an rpg especially if you plan on instancing the same player object but changing the graphics and stats of that instance to the member of the corresponding slot id.

That’s basically it for state machines, it’s pretty simple but like I said you can make this far more complex (which makes no sense) but you certainly could for the sake of doing so.   

  • Rukiri 6/5/17 

Leave a Comment

Your email address will not be published. Required fields are marked *