playMaker

Author Topic: broadcast a event from script [implemented]  (Read 6478 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14035
  • Official Playmaker Support
    • View Profile
broadcast a event from script [implemented]
« on: April 08, 2011, 05:06:05 AM »
Hi,

 It seems that being able to broadcast an event globally to all fsm is not possible from script. I have to have a reference of a fsm component, send an event to it that will eventually broadcast an event to all fsm... not ideal.

 It would be much better to have that available without any fsm reference. It would be a static function of PlayMakerFSM or something like:

PlayMakerFSM.SendEventToAll("EVENTNAME").

 Am I off the map with this? Is it actually possible already? We might be missing a proper api reference isn't it :)

Bye,

 Jean


« Last Edit: September 30, 2011, 07:19:35 PM by alexchouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3570
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: broadcast a event from script
« Reply #1 on: April 08, 2011, 04:56:01 PM »
I'll add this to the API...

In the meantime you should be able to use BroadcastEvent.cs as a starting point to make your own function. You shouldn't need a reference to an FSM component... just iterate through all FSMs and send an event to each one. (Use FSM.FsmList).

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14035
  • Official Playmaker Support
    • View Profile
Re: broadcast a event from script
« Reply #2 on: April 10, 2011, 09:59:07 PM »
hi,

 Good point! Did not crossed my mind at all... I guess I was looking from a "feature request" point of view, rather than do-it-yourself which is fine as well.

 Bye,

 Jean

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3570
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: broadcast a event from script
« Reply #3 on: September 30, 2011, 07:18:47 PM »
Broadcast event is now in the API - see SendEvent.cs for an example.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14035
  • Official Playmaker Support
    • View Profile
Re: broadcast a event from script [implemented]
« Reply #4 on: October 02, 2011, 10:14:14 PM »
thank you!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14035
  • Official Playmaker Support
    • View Profile
Re: broadcast a event from script [implemented]
« Reply #5 on: October 27, 2011, 11:11:41 PM »
Hi Alex,

 ok, I have implemented the new way to broadcast.But you'll see that I still have to access the list of fsm and take the first one to be able to send. Is that ok? I think it's because the context in which I am trying to broadcast an event is not an Fsm Action, it's an external script that has not relation with any Fsm at all. It's just a proxy that will broadcast an event. So I still find odd that I have to get an Fsm to actually broadcast. Is it because the event has to have a "source"? Or I am missing something again :) ?


   
Code: [Select]

                FsmEventTarget eventTarget = new FsmEventTarget();
eventTarget.target = FsmEventTarget.EventTarget.BroadcastAll;

var fsmList = new List<Fsm>(Fsm.FsmList);
if (fsmList.Count>0){
Fsm fsmOne = fsmList[0];
fsmOne.Event(eventTarget,anEvent);
}

              //foreach (var fsm in fsmList){fsm.Event(anEvent);}

Bye,

 Jean

playmakerNewb

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: broadcast a event from script [implemented]
« Reply #6 on: December 08, 2011, 07:33:25 AM »
jeanfabre,

Did you ever find a solution to your last post?

I have a script attached to a non-fsm gameobject.  I want to broadcast global events out to all available FSM's.  It seems that right now, I need to know the name of each FSM in order to do this...correct?

plang

  • Playmaker Newbie
  • *
  • Posts: 1
    • View Profile
Re: broadcast a event from script [implemented]
« Reply #7 on: December 13, 2011, 03:30:49 AM »
jeanfabre,

Did you ever find a solution to your last post?

I have a script attached to a non-fsm gameobject.  I want to broadcast global events out to all available FSM's.  It seems that right now, I need to know the name of each FSM in order to do this...correct?

Another newbie, same problem! How are we supposed to broadcast an event to all FSMs from code? Having a look at SendEvent.cs did not help. Is there something new in the API meanwhile?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14035
  • Official Playmaker Support
    • View Profile
Re: broadcast a event from script [implemented]
« Reply #8 on: December 13, 2011, 04:02:36 AM »
Hi,

 Nop, I think it's still the way I do it ( holding a reference to one fsm, doesn't matter which one), then iterate through each and send event. the api might provide a better way, but Ia m not aware of it.

 Bye,

 Jean

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3570
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: broadcast a event from script [implemented]
« Reply #9 on: December 13, 2011, 11:02:40 AM »
If you have a reference to an FSM you can just use BroadcastEvent(). No need to make an EventTarget.

I'll add a static method to the next update so you don't need an FSM reference.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3570
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: broadcast a event from script [implemented]
« Reply #10 on: December 20, 2011, 10:04:56 PM »
Jean, when you get a chance, please test the static PlayMakerFSM.BroadcastEvent methods in the beta. Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14035
  • Official Playmaker Support
    • View Profile
Re: broadcast a event from script [implemented]
« Reply #11 on: December 20, 2011, 10:16:37 PM »
Hi Alex,

 I did and it worked, I did not report on this sorry Alex ( tho found a quirk with the log window yesterday, ticket coming soon).

 Bye,

 Jean

whydoidoit

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: broadcast a event from script [implemented]
« Reply #12 on: January 04, 2012, 10:31:17 PM »
The static method sounds very useful - probably being thick, but I can't find the beta!  Is that something that needs registering for?

playmakerNewb

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: broadcast a event from script [implemented]
« Reply #13 on: February 22, 2012, 11:41:05 AM »
Alex,

Thanks for this update.  The static sendevent method was exactly what I needed to solve my problem!