Biphe wrote:Hmm... What is a finite state machine?
At a theoretical level, a finite state machine is simply a set of states and the acceptable transitions between those states.
Using your character as an example, you have the following states: standing, crouching, walking, jumping. When in a jumping state, I should be unable to transition to any other state (except perhaps crouching). When crouching I should be unable to jump or walk (unless we're talking about crabwalking), but standing is okay.
Basically your current state restricts the allowable transitions, while circumstances determines which state to transition to. So, for example, I press jump but I'm currently crouched. Nothing happens, because state forbids it.
This is often used in AI as well. If I get too close, an enemy could enter a defensive state, engaging cautiously. When within striking distance they could enter an attack state. There's no way for an attack state to go anywhere but a defensive state. In defensive mode danger is determined and attack decision are made.
Usually finite state machines are described by enums and case switch statements, both of which are not so simple in lua. Still, it's often worth it.
Sorry if this explanation isn't so clear. I tried.