playMaker

Author Topic: PlayMaker events  (Read 2139 times)

jjahuijbregts

  • Playmaker Newbie
  • *
  • Posts: 2
PlayMaker events
« on: September 09, 2015, 04:50:32 PM »
Hi, I'm developing my own asset; Inventory Pro, which has PlayMaker support, but currently doesn't push it's events onto PlayMaker.

A few quick questions,

- Can I add my own events to the event browser without the user having to define them (compile time?)?
The solution I currently have in mind would require the user to manually define each event (string based), which could then be fired from Inventory Pro.
Even though this should theoretically work it would be rather error prone, as a typo can be easily made, plus the user would require to use the documentation to verify the event names.

- I can trigger events using myFsm.Fsm.Event(eventName); but can I also send variables? ( For example, when looting an item I'd like to send the looted item with the event ).
Assuming this is possible, how would I go about doing this? If not, I could create a global variable to store the items into, but with many events this could turn into quite a mess. Especially if the user has to manually define the event name, as well as the global variable to store the events args into.

Any feedback is more than welcome :)

Cheers,
Joris
« Last Edit: September 09, 2015, 04:52:09 PM by jjahuijbregts »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: PlayMaker events
« Reply #1 on: September 10, 2015, 01:42:12 AM »
Hi,

 It's great to see you want to support PlayMaker, don't hesitate to get in touch with me if you need help.

What I do when I port assets to PlayMaker is creating a prefab that the user put on the scene and that prefab has a totally empty Fsm, that simply has all the events needed for this particular Asset. you can see how it's done for example in the uGui package on the Ecosystem

If you want to do that programmatically within your system, it's simple:

Quote
FsmEvent myEvent = new FsmEvent("MY ASSET / SOME EVENT");
myEvent.IsGlobal = true;
FsmEvent.AddFsmEvent(myEvent);


Notice the "/", I personally recommend using this as a delimiter so that the list of events is properly organised especially in dropdown selections, in your case, "INV PRO" or something would do as "INVENTORY PRO" is quite long. It's only a suggestion, you are free to call your events anything.

To send variables with events, set the
Quote
HutongGames.PlayMaker.Fsm.EventData
prior sending the event.

If you have complex data ( multiple values of the same type), you'll need your special event data, but it's fine and works well, I made several versions of that, let me know if you think you need this, I can point you to some examples and explain more in details.


Bye,

 Jean