playMaker

Author Topic: Triggering an FSM from a script  (Read 5164 times)

random1

  • Playmaker Newbie
  • *
  • Posts: 14
Triggering an FSM from a script
« on: June 29, 2013, 01:34:39 PM »
I have an FSM that, after a certain point I want to wait for a trigger/event from a script.
How do I do this?
From the previous versions of this question I can find here, it seems GlobalTransition might be the way to go but:
a) How do set them up in PlayMaker (a pointer to a good tutorial would be nice)
b) How do I trigger one with a (C#) script.
Thanks.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Triggering an FSM from a script
« Reply #1 on: July 01, 2013, 03:04:13 AM »
Hi,

 You can broadcast a global event from script by calling this:

Code: [Select]
using HutongGames.PlayMaker;
(...)
PlayMakerFSM.BroadcastEvent("GLOBAL HELLO");

If you want to fire an event to a specific Fsm, you can do this:

Code: [Select]
FsmOwnerDefault goTarget = new FsmOwnerDefault();
goTarget.GameObject = new FsmGameObject();
goTarget.GameObject.Value = this.gameObject;
goTarget.OwnerOption = OwnerDefaultOption.SpecifyGameObject;

       // send the event to this gameObject and all its children
FsmEventTarget eventTarget = new FsmEventTarget();
eventTarget.excludeSelf = false;
eventTarget.target = FsmEventTarget.EventTarget.GameObject;
eventTarget.gameObject = goTarget;
eventTarget.sendToChildren = true;

// create the event.
FsmEvent fsmEvent = new FsmEvent("HELLO");

// send the event
fsmProxy.Fsm.Event(eventTarget,fsmEvent.Name);



fsmProxy being a reference to a PlayMakerFsm component.

You can see it in action in the Photon bridge itself:
PlayMakerPhotonProxy.cs
PlayMakerPhotonGameObjectProxy.cs

Does that help?

bye,

 Jean

random1

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Triggering an FSM from a script
« Reply #2 on: July 01, 2013, 03:30:00 PM »
Hi Jean,
Thanks, that should hopefully do it. I guess the global broadcast is received by all FSM's in the project?

---
The script to call a specific FSM seems rather long-winded; I'm surprised it's not a single function call like the global broadcast.

I think for the duration I'm just going to use global broadcasts. They seem easier. :-)

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Triggering an FSM from a script
« Reply #3 on: July 02, 2013, 02:48:15 AM »
Hi,

 Broadcasting an event is *only* received by Active Fsms that implement that event specifically. So yes all fsm with that event will get it.

bye,

 Jean