playMaker

Author Topic: Send Event to Sub FSM from script[SOLVED]  (Read 4130 times)

BigDog

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Send Event to Sub FSM from script[SOLVED]
« on: May 30, 2015, 04:15:03 PM »
In my effect to practice good software engineering, I am trying to use "Run FSM" more. But I have come to a roadblock. I can't send event directly to the 'sub FSM'.

Before I used 'sub FSM', I have a state waiting on a event which gets send from C# script. Now this state is moved into the template. And it no longer received the event. How can I get send a event to a sub fsm?

Thanks
« Last Edit: July 02, 2015, 05:57:01 AM by jeanfabre »

BigDog

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: Send Event to Sub FSM from script
« Reply #1 on: May 30, 2015, 04:41:01 PM »
Hi, I just solved my own problem.

The trick is to use the obscure FSM property of the fsm.

Code: [Select]
HutongGames.PlayMaker.FsmEventTarget etarget = new HutongGames.PlayMaker.FsmEventTarget();
etarget.target = HutongGames.PlayMaker.FsmEventTarget.EventTarget.SubFSMs;

m_MovementFSM.Fsm.Event(etarget, "arrived");

Thanks.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14198
  • Official Playmaker Support
    • View Profile
Re: Send Event to Sub FSM from script
« Reply #2 on: June 03, 2015, 12:49:12 AM »
Hi,

 You have two entry point, PlayMakerFSM and FSM, PlayMakerFSM is the component itself ( that is dropped onto the GameObject), while the FSM is the actual class representing the fsm ( the visual canvas).

and so PlayMakerFSM compose some of the methods of FSM but no all. hence why some of the stuff is done via .Fsm

 Bye,

 Jean

BigDog

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: Send Event to Sub FSM from script
« Reply #3 on: June 26, 2015, 03:10:50 PM »
I come across another issue with sending event to sub fsm. The issue is it doesn't work after one level of sub fsm. Is this by design or is this a bug? This makes the template system very limiting.

Thanks

BigDog

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: Send Event to Sub FSM from script
« Reply #4 on: June 26, 2015, 03:33:53 PM »
I eventually managed send event to second level sub fsm from script. The trick is to set the events to global event, which I needn't had to do with the first level sub fsm.

Thanks

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3615
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Send Event to Sub FSM from script
« Reply #5 on: June 26, 2015, 06:25:27 PM »
You can access sub FSMs directly using this property of Fsm:
public List<Fsm> SubFsmList

Then you can call Event(string eventName) or Event(FsmEvent event) on the sub FSM directly.


BigDog

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: Send Event to Sub FSM from script
« Reply #6 on: June 27, 2015, 04:28:12 PM »
Great! That's what I need. Thanks!