playMaker

Author Topic: Working with multiple FSMs  (Read 2909 times)

valyard

  • Playmaker Newbie
  • *
  • Posts: 8
Working with multiple FSMs
« on: November 06, 2013, 05:43:25 PM »
Hi.

I'm trying to create something complex using Playmaker and I found that it's really hard to communicate between FSMs. So, do I understand correctly that this is THE way to do:
- save a float with Set Event Data
- Send Event a global event
- react to a global event
- read a float with Get Event Info ?

What if I want to pass multiple floats?
What if I send multiple events to multiple FSMs at once? How do they share global event info?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Working with multiple FSMs
« Reply #1 on: November 06, 2013, 05:54:46 PM »
I've never even used the Set Event Data action, I store everything from the other actions that collect or define the data, then send them to the FSMs that need it with Set FSM Float/Int/Game Object. You could use Global Variables if you're sending to a bunch of other FSMs, or store it all on one "library" object and have them check that object for an update.

Can you clarify the scenario a bit?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

valyard

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Working with multiple FSMs
« Reply #2 on: November 06, 2013, 06:03:02 PM »
Just one main FSM and several slave FSMs as Objects in OOP sense.
So, I basically want to "call" methods on them which internally change state.
For example I would have UpdateData(float, float) method on SlaveFSM1 and would like to call it and use it to send two floats from MasterFSM. Or SlaveFSM2 might have a method SetPositions(Vector3, Vector3, Vector3).

Setting variables on slave FSMs looks very non-OOP style.
Having a separate proxy object to store data looks like a hack but might be viable for a while.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Working with multiple FSMs
« Reply #3 on: November 06, 2013, 09:51:16 PM »
Typically if you want to share variables just mirror the variable name/type in the other FSM, then use Set FSM Float (or whichever) and choose the target object to affect.

You also have Call Method and Invoke Method actions you can use, which is probably more likely what you're looking for. Have you checked those actions out?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Working with multiple FSMs
« Reply #4 on: November 07, 2013, 02:05:25 AM »
Hi,

 I created a small framework with new actions to allow sending unlimited number of properties per event:


http://hutonggames.com/playmakerforum/index.php?topic=4296.msg20172#msg20172

 basically, you define a number key and their variables, so you only define what you need, it's a lot cleaner in your state and actions stack.

Bye,

 Jean

valyard

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Working with multiple FSMs
« Reply #5 on: November 07, 2013, 02:12:54 AM »
Thanks jeanfabre.
I'm trying your plugin but I keep getting this error:

Quote
NullReferenceException: Object reference not set to an instance of an object
HutongGames.PlayMaker.FsmVariables.GetVariable (System.String name)
HutongGames.PlayMakerEditor.FsmSearch.FindVariableInField (System.Type fieldType, System.Object fieldValue)
HutongGames.PlayMakerEditor.FsmSearch.FindVariableUsage (System.Object obj, Int32 currentDepth)
HutongGames.PlayMakerEditor.FsmSearch.DoSearch ()
HutongGames.PlayMakerEditor.FsmSearch.Update ()
HutongGames.PlayMakerEditor.FsmSearch..ctor (HutongGames.PlayMaker.Fsm fsm)
HutongGames.PlayMakerEditor.FsmSearch.GetSearch (HutongGames.PlayMaker.Fsm fsm)
HutongGames.PlayMakerEditor.FsmSearch.Update (HutongGames.PlayMaker.Fsm fsm)
HutongGames.PlayMakerEditor.FsmEditor.OnInspectorUpdate ()
FsmEditorWindow.OnInspectorUpdate () (at Assets/PlayMaker/Editor/FsmEditorWindow.cs:327)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj)
UnityEditor.HostView.Invoke (System.String methodName)
UnityEditor.HostView.OnInspectorUpdate ()

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15496
  • Official Playmaker Support
Re: Working with multiple FSMs
« Reply #6 on: November 07, 2013, 02:14:59 AM »
Hi,

 Are you using the latest Playmaker Version?

bye,

 Jean

valyard

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Working with multiple FSMs
« Reply #7 on: November 07, 2013, 02:21:21 AM »
Just updated to the latest version.
Seems to be ok. Sorry for that q:

@Lane
Checking out Call Method action, I saw Invoke Method one but somehow missed it.