Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought

Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Author Topic: Using State Machines - who is reponsible for state transitions?  (Read 7472 times)
Jr. Member
Posts: 11

View Profile Email
« on: January 12, 2009, 08:28:40 »

Hey all. I know this is not _specifically_ about Pmvc, but i will be using the new StateMachine util soon, and this question relates to that...

I'm using Finite State Machines (fsm) in one of my games right now. I'm running into a problem where i don't know where/who should be responsible for triggering a state change. Should the state class itself monitor everything and determine if a state change is required, or should the "state owner" take care of that stuff?

I've got some "actors" moving around on stage, and their movement is controlled via states - walk, rest, moveTo, etc etc.

Since i'm going to be using the StateMachine Util that comes with PMVC soon, i'm going to want to know the answer in relation to that tool too...

Any suggestions would be most appreciated.

Neil Manuell
Courseware Beta
Sr. Member
Posts: 109

View Profile Email
« Reply #1 on: January 12, 2009, 11:57:08 »

Are your states purely encapsulated within your characters, or are they dependant on higher level state changes?

I think that maybe you are confusing the State Pattern with a Finite State Machine.

the State Pattern would control the different states within your characters (walking, running, etc)
a Finite State Machine would control the higher level application states (loading, practice mode, saving).

They could of course both be used together.

Global Moderator
Hero Member
Posts: 2871

View Profile WWW Email
« Reply #2 on: January 12, 2009, 06:15:40 »

In short, at this time your application is responsible for foguring out when to send the actions that trigger state transitions. There are it could be that some transitions are conditional; logic has to be executed to determine whether to actually transition. This is best done in a command triggered by  the exiting notification for the current state. It can examine the destination state and determine if its ok to transition. If not it sends StateMachine.CANCEL and nothing happens. Otherwise, it does nothing and allows the transition to begin. It might even kick off a hiding animation to sweep away the current state's ui. Then a command rsponding to the entering note for the destinatin state fires and presents its ui.

Pages: [1]