Last night I wrote a tutorial on Finite State Machines - you might find it useful.
http://hacking.majenko.co.uk/finite-state-machine