playMaker

Author Topic: How to set up Metadata FSM?  (Read 2518 times)

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
How to set up Metadata FSM?
« on: October 06, 2019, 12:21:49 PM »
Hello,
I have read about using Metadata FSM to store public variables. But I'm still not sure enough about how it works & how will it affect my workflow. Can you explain it further about it?
Wouldn't it be a mess if there are so many sources(inside/outside of the organ) that can change its value?


Maybe a case example will help a lot to understand the concept.
Thank you!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to set up Metadata FSM?
« Reply #1 on: October 07, 2019, 02:59:59 AM »
Hi,

 yes, you need to be disciplined if you have a meta data fsm, the same applied even on regular c#, without discipline, you can mess up a project amazingly quick :)

so, I use meta data fsm for characters for example.

all data that many of the fsm within the hierarchy of that character will need will have their "authoritative" source in that meta data fsm. that's of for reading.

for writing, you can go with two options

-  directly write to the metadata fsm properties, like health or ammo for example, the downside is that other fsm will not be made aware of this and watching a variable on everyupdate is lame...

- create an event for each or a common one ( "REFRESH" or something), so that if an fsm is willing to change the value of a meta data it must do so using the dedicated event, "PLAYER / METADATA / SET XXX" and pass the value you want to change with the event. The direct benefit is that any fsm can listen to it and instantly use the value, sometime when things get complex and that other fsm are deducing their own values based on a different property, I introduce a next frame event delay when I know that work will be done and that many other values will change because of that, then I proceed with the logic of that fsm.

inside the organ is easier than outside the organ is an interested challenge, many times I use the meta data as a rule between organs for communication, that's expecially useful for prefab instances, for example, I have many different weapons prefabs, but if I have one instance, I expect a metadata fsm on it with power, ammo, damage, etc etc. this way, it becomes very powerful! I don't care what the weapon is, as long as it conforms to the contract that it must have a meta data. same with pickups, anything you trigger should have a metadata with a type, ( pickup, bomb, health pack, what ever) and anything interacting with it first query for it, then its type and then knows what to do with it.

that's for reading, and for writing, I also use dedicated events.

 so, again, it's only a matter of being very strict with your convention ( the usual convention vs configuration type of logic), and then things become very powerful, flexible and maintainable, because you expect things to be handled in a very specific and reliable way. that's all there is to it.

Bye,

 Jean

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
Re: How to set up Metadata FSM?
« Reply #2 on: November 03, 2019, 08:33:35 AM »
Hello Jean,

do you have a quick in-game example to see it in action?

I'm having a dilemma whether the metadata should be used just for information OR it could be better if other FSM can write to the metadata and then the Metadata FSM passes up the value to respective variables.

Ex: the 'player Speed' variable is in Player Controller FSM & also available in Metadata FSM. Then other FSM can simply change the 'player Speed' directly by writing into Metadata FSM, which then gets forwarded to the Player Controller FSM.

Sorry, I might be just getting confused by how it really works.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How to set up Metadata FSM?
« Reply #3 on: November 03, 2019, 03:39:21 PM »
Hi.
This is the way i use this :

On an enemy on the object where i have a trigger, i have a fsm called Data.
In there i hold several stats of the enemy.
For example : Current Health , maximum health, Elemental weakness.
Also Child objects that i need to communicate with.

Then i have different fsm's on the same or other child/parent objects.

For example a health manager, damage manager and so on.
then use fsm actions to read and change the Health variable on the Data object.

You can find many custom fsm actions on the ecosystem. (for example Fsm Float Add, Fsm Float Compare, etc) which i use a lot,

On player i would have a Data fsm as well.

And then i have 1 Global data which i call Meta Data and also have set this as a global variable.

This one Manly Holds Reference Data (references to gameobject, array list references, easy save references etc) and for example a item database.

for your player Speed example i would have the data on the meta and then on the Player Controller FSM (or a separate fsm) and use the action "Fsm Float Changed" (Ecosystem)

When float on the Metadata FSM is changed, change it on the Player Controller FSM

But you could also only have a reference on the 'Metadata FSM' to the object that holds the 'Player Controller FSM'
And handle the speed directly.

it kind of depends on the usage.

Another thing i tend to do is use the "Data" to set start values.
I set the data (for example 'Walk Speed) and on start i use 'Set Fsm Float' to set it on the object that handles the speed.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to set up Metadata FSM?
« Reply #4 on: November 04, 2019, 02:23:22 AM »
Hi,

 Meta data should just store data and possible process incoming data but not try to set data to other fsm, a meta data fsm should be totally blind and not know who will wants data, other fsm must know about this convention that for a given object or prefab or pick up item, there must be a meta data fsm with some known variables, and they must use GetFSMXXX for this.

 This is in my opinion the most effective, reliable and safe way to do this.

Bye,

 Jean