What is a (Finite) State Machine? Why are they useful for game dev?

Started by
11 comments, last by Pandamoneum 11 years, 5 months ago

Thanks SiCrane and Iride for the replies. So, to use your examples SiCrane, what is the benefit of actually doing it that way? Is it just a "different" way to approach the architecture of the game? Or does thinking about the game in that way provide real benefits in terms of efficiency or clear coding?

auryx


To answer your question directly, efficiency of execution is not the point or intent of a FSM. FSM's are used to break down game logic into easily managable units for the human programmers. E.g., it's useful for making your code easier to read, easier to understand and easier to maintain. It has the added benefit of making bugs easier to find (part of the maintenance I mentioned).

EDIT: I see apatriarca already beat me to this description... ;)

-Lead developer for OutpostHD

http://www.lairworks.com

Advertisement
Thanks for the reply anyway, leeor_net - it's still useful to get different people's perspectives on this!
I want to take a shot at this. One, to try and help, and two, to be corrected if I'm wrong since I still consider myself a novice.

When I think of FSMs, I think of things like the previous posters have said, but I wanted to try and give a different visual to help you (hopefully not confuse you). For example, this is one path a user could take in a FSM:

[color=#008000]Splash Screen -> Main Menu -> MultiPlayer Menu -> Find Room -> Game Begins -> Pause (Player Quits) -> Multiplayer Menu (Player backs out) -> Menu Menu -> and so on.

Now, Iride said something in his first post about a state having a subset. So, I will give you an example of some states I believe could have subsets, and those states would manage their own subsets.

Subset 1: Main Menu (Which, remember, is being managed by some other FSM)
[color=#b22222]Main -> Options (Player goes back) -> Main -> Help (Player goes back)[color=#B22222] -> Main -> Multiplayer is clicked, which effects the manager taking care of Main Menu (My above FSM in bold-green).

[color=#008000]MultiPlayer Menu -> Find Room -> Game Begins -> Pause

Maybe the pause menu can have its own FSM?

So, that is my answer. I tend to think of FSMs as managers, and I usually give them that type of name (StateManager, MenuManager, etc). I hope I was able to help.

If anyone thinks I don't know what I'm talking about, please correct me as it's always fun to learn!

This topic is closed to new replies.

Advertisement