playMaker

Author Topic: FsmVariables.GetFsmString question  (Read 2427 times)

Jim W

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 9
FsmVariables.GetFsmString question
« on: August 16, 2013, 02:55:29 PM »
Hi,

I'm using the following code from a custom script and thought that the "newVar" would automatically get created, yet when I look in the Variables section for the FSM or in the Globals list of variables, it does not show up. 

FsmString test = this.behavior.FsmVariables.GetFsmString("newVar");

I sent an event that did not exist and it created and added the new event to the Events tab and persisted the new event even after I stopped the app.  I was thinking the same would happen for new variables.?  Is this a bug?

I'm exploring ways of integrating logic between Playmaker and my custom scripts.

Thanks, Jim

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: FsmVariables.GetFsmString question
« Reply #1 on: August 16, 2013, 05:36:41 PM »
Are you trying to add a variable in the editor at design time? Or at runtime?

There are different approaches depending on what you're trying to do...

Jim W

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 9
Re: FsmVariables.GetFsmString question
« Reply #2 on: August 16, 2013, 08:00:51 PM »
I'm adding the variable at runtime, via the call to GetFsmString, which is suppose to add it if it doesn't already exist.  So at run time, I was expecting to then see the variable show up in the editor as proof of that (and maybe for debugging).  After runtime, I was hoping to see it permanently added as a variable. That's the way that it works when you send events via code, that do not already exist..

The expected behavior seemed useful for making scripts that interact with Playmaker by reducing some of the Playmaker specific setup tasks.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: FsmVariables.GetFsmString question
« Reply #3 on: August 16, 2013, 08:35:13 PM »
I'll look into why the variables don't show up when added by script at runtime. It could be a caching issue... did you try restarting the Playmaker editor to see if they show up while running?

However, without doing something extra, variables added at runtime will be lost when you stop the game. You're changing a runtime copy of the PlayMakerFSM component that is destroyed when you stop playing. There are third party utilities to save changes made at runtime, Playmode Persist comes to mind, but I can't remember if they work with Playmaker or not...

Prefabs and templates are an exception to this rule, since they are persistent project assets (not scene objects). Changes made to them at runtime ARE persistent.

The event list is kind of unique since it doesn't exist as an asset or a MonoBehaviour. It is constructed on the fly when FSMs register their events. You see the added event survive playmode change because the list isn't cleared when you stop the game. But the event hasn't really been added to the FSM... if that makes sense!

EDIT: I would recommend adding the variables at edit time, maybe with a small editor tool.
« Last Edit: August 16, 2013, 08:38:57 PM by Alex Chouls »