playMaker

Author Topic: state changes and Enter, Update, Exit action groups  (Read 1127 times)

spinlock

  • Playmaker Newbie
  • *
  • Posts: 2
state changes and Enter, Update, Exit action groups
« on: November 18, 2015, 09:56:21 PM »
I've made my own FSM's in the past, and I'm used to working with them in the following way when managing states, in pseudocode:

MaybeChangeState(NewState):
  if CurrentState == NewState return
  CurrentState->OnExit()
  CurrentState = NewState
  CurrentState->OnEnter()

// Called every frame.
UpdateState():
  CurrentState->Update()

This gives me the chance to execute some code when the state is entered, when the state is currently "active", and when we exit the state, which is immensely helpful in structuring my game.

I saw a thread from 2011 asking about the same functionality, and a fellow suggested "action groups", where we have 3 groups: Enter, Update and Exit.   Then you just put your actions you want to run when the state is entered in the Enter group, actions you may want to run every frame in the Update group, and actions you want to run when we exit the state in the Exit group.  This would probably require a Change State(NewState) type of action so you could have the system call the appropriate Enter and Exit action groups.   

Maybe this style of doing things just doesn't quite fit with the Playmaker style?  Am I just crazy?!?!  The one thing that immediately jumps out at me that would break are actions that have the run every frame bool checked -- that wouldn't work on Enter and Exit action groups, though I would imagine it could be smart enough to disable this when in any groups other than Update.

This would actually be REALLY cool to have this!  But, in the meantime, does anyone have any suggestions on how I could maybe simulate this? 
« Last Edit: November 18, 2015, 10:14:40 PM by spinlock »