playMaker

Author Topic: Saving a playmaker FSM component  (Read 2127 times)

Sanguinius

  • Playmaker Newbie
  • *
  • Posts: 2
Saving a playmaker FSM component
« on: January 09, 2017, 03:28:13 AM »
Hello,

i was redirected to here from the Easy Save 2 forums so i'll repost what I said.

I know you can use the "save all" method within playmaker to save all the FSM variables, but are you able to manually save the entire FSM component using a script?

I'm attempting to save both the transform and the FSM component. The transform is easy to save, but I don't know how to properly grab the FSM.
You usually do something like:
Code: [Select]
Transform t = obj.GetComponent<Transform>();
ES2.Save(t, file+"?tag=transform");
ES2.Load<Transform>(file+"?tag=transform", t);

But how can you get that objects FSM? I was thinking something like:
Code: [Select]
FsmVariables f = obj.GetComponent<FsmVariables>();
But I haven't made much progress with it.
(Just to be a bit more clear i'm trying to save this with all the variables set inside http://prntscr.com/dt88s5)

Thank you.

*Original Post http://moodkie.com/forum/viewtopic.php?f=5&t=1103&p=3324#p3324

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Saving a playmaker FSM component
« Reply #1 on: January 10, 2017, 02:28:16 AM »
Hi,

 indeed, you'll have to do this manually, going over all the FsmVariables and save the name, type and value of each variables, or just the name and value if you simply want to save progress or something.

so you need to make a hashtable looking like this:

"My float":3.2
"My Int": 1
"My String": "hello"

and you save this in easySave.

 Bye,

 Jean

Sanguinius

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Saving a playmaker FSM component
« Reply #2 on: January 11, 2017, 10:23:41 PM »
Thanks, you put me on the right track. I need to be able to save multiple components not just one. So I can do something like this:

Code: [Select]
    private FsmVariables globalVariables;

    public FsmBool[] globalBoolVariables;
    public FsmInt[] globalIntVariables;
    public FsmFloat[] globalFloatVariables;
    public FsmString[] globalStringVariables;
   

    public void SetGlobalVariables()
        {
            FsmVariables.GlobalVariables.BoolVariables = globalBoolVariables;
            FsmVariables.GlobalVariables.FloatVariables = globalFloatVariables;
            FsmVariables.GlobalVariables.IntVariables = globalIntVariables;
            FsmVariables.GlobalVariables.StringVariables = globalStringVariables;

        }

And then save each variable from there.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Saving a playmaker FSM component
« Reply #3 on: January 12, 2017, 01:04:59 AM »
Hi,

 sort of, here you seem to want to save global variables, which are not the same as the variables defined in a single Fsm. But yeah, saving multiple component will mean structuring your data per Fsm.

Bye,

 Jean