playMaker

Author Topic: How to tell from script if a FSM is currently running  (Read 3141 times)

vsouders

  • Playmaker Newbie
  • *
  • Posts: 2
How to tell from script if a FSM is currently running
« on: June 16, 2011, 11:08:10 AM »
Is there a perferred way to tell if a FSM is currently executing (or what state is active) from within C#? 

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to tell from script if a FSM is currently running
« Reply #1 on: June 17, 2011, 07:03:37 AM »
Hi,

 I am not sure I understand what ou mean by "running"

 each fsm is a component like any other, nothing so special about it from a gameobject point of view. So if you disable a fsm component it will not run. And from a script, you can simply hold a reference or search for fsm component attached to a game object and check if it's enabled or not. Is that what you are after? if yes, I can explain further how to do just that.

 Now, if that's not what you are after. What do you mean by "running": that it is currently processing a state and its actions? that it's idling somehow on a state waiting for an event to trigger?
I often have my "StART" event state totally empty when that fsm is only supposed to react to global event. and I always name it "idle" because visually, nothing (yet :) ) gives me a clue that it's doing nothing. In that case, I would set up a convention system within your project so that an idle state would be named precisely "idle" or at least contain that word, and with the playmaker api, you can get the current active state, you then check the name and if it contains "idle" then you know.

 Check this action for some api reference on how to access the current state of an fsm.

https://hutonggames.fogbugz.com/default.asp?W480

Alternativly, you could also maintain variable  "idle" for each fsm that is supposed to expose such behavior, and set it accordingly in each key states.


Hope it helps. If not, can you define a bit more what you are after?

 Bye,

 Jean