playMaker

Author Topic: Creating FsmInt in custom action  (Read 3055 times)

mn6000

  • Playmaker Newbie
  • *
  • Posts: 17
Creating FsmInt in custom action
« on: September 23, 2016, 06:13:56 PM »
Is it possible to create a FsmInt variable during a custom action?

I have an action which loads json and sets fsm variable values. I'd like to do this dynamically and not have to create the fsm variables before hand.

This is what I'm doing:

Code: [Select]


...
[Serializable]
public class ItemsList{
public string item_applemuffinbatter { get; set; }
public string item_applemuffins { get; set; }
public string item_applepie { get; set; }

}

...

PlayMakerFSM fsm;

TextAsset asset = Resources.Load(Path.Combine("Json","items")) as TextAsset;

ItemsList itemsList = JsonUtility.FromJson<ItemsList> (asset.text);

foreach(PropertyInfo prop in typeof(ItemsList).GetProperties())
{


FsmInt intVariable = Fsm.GetFsmInt(prop.Name);
intVariable.ShowInInspector = true;

}

In this case GetFsmInt returns an int variable but I don't see it in the variable panel.

Is it possible it's creating it but it won't be visible?

Thank you.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating FsmInt in custom action
« Reply #1 on: September 26, 2016, 03:54:10 AM »
Hi,

 yes, you can indeed create on at runtime, but there are no practical case really, since an FsmInt is supposed to be the link between the developer and PlayMaker via the interface of actions and fsm, so it makes no sense to not make this a public field so that it becomes available during editing somehow within the PlayMaker interface.

what are you trying to achieve? to save json data, it is expected that the developer knows what to expect, else json should be kept as is, and search performed somehow to find a potential value that is of interest inside this json.

 Bye,

 Jean

mn6000

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Creating FsmInt in custom action
« Reply #2 on: September 26, 2016, 05:45:51 PM »
Hi Jean, for content management purposes we found it easier to drive fsm variable data from json dynamically. 

I first attempted to do this all in C# but was warned that using reflection would be inefficient.

It's fairly easy to use python to generate an entire class using json as it's source. Currently the only downside is having to manually create all the fsm variables to store the data.

Thank you.

Noah




« Last Edit: September 26, 2016, 08:50:25 PM by mn6000 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating FsmInt in custom action
« Reply #3 on: September 27, 2016, 03:24:52 AM »
Hi,

 I am still unsure about why you think using Fsmxxx classes is the way to go if you are not going to use them as interfaces to your developers?

Maybe you should look at DataMaker and XmlMaker and see how I went about this, it may give you some ideas ( not that my take on this is the only way to go :) )

Bye,

 Jean

mn6000

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Creating FsmInt in custom action
« Reply #4 on: September 27, 2016, 04:39:41 PM »
Hi Jean, thank you. I'll check Datamaker and XmlNodeAction, what's the name of the function I'm looking for?

Right now the json is the interface between the designers and developers. 

We are a small team and mostly non-developers.

There's no more efficient way to input tuning data for items in the game than editing a json.

Noah

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating FsmInt in custom action
« Reply #5 on: September 28, 2016, 08:03:12 AM »
 Hi,

 Yep, however I would strongly recommend xml instead of json, Xml has xPath, which allow crazy powerful searches within your data. With json, you can't and it's a shortcoming that hits hard when after many months of development, json becomes a bottleneck because of the lack of search within the data.

 So consider this very carefully. You can also do json to xml conversion which helps as well. I built one, let me know if you need more info on this.

Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating FsmInt in custom action
« Reply #6 on: September 28, 2016, 08:04:11 AM »
:) did not reply to your first question

 Check out the custom classes that make up the actions, they feature FsmVariables inside them and are serialized.

Bye,

 Jean

mn6000

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Creating FsmInt in custom action
« Reply #7 on: October 31, 2016, 06:31:23 PM »
hi Jean, I've spent a couple weeks looking for an example of a new fsm variable created at runtime but cannot find one.

Where should I be looking?

Thank you.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating FsmInt in custom action
« Reply #8 on: November 01, 2016, 02:30:37 AM »
Hi,

 Inside XmlMaker, you'll have a c# file called FsmXmlSource

That class is managed by code and inside this class you'll have public variable of type FsmString and FsmGameObject for example.

Bye,

 Jean