Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: coxy17 on December 20, 2017, 06:26:15 AM

Title: Add variable to FSM during edit mode [SOLVED]
Post by: coxy17 on December 20, 2017, 06:26:15 AM
Hi

Im using a custom editor window and I want to be able to add a new variable when i press a GUI button using the API, but the only guide i found was accessing the fsm variable array and then adding the new value to it but I dont need to find it but just add.

I can see there is a FindFSMString and GetFSMString but is there something like a AddFSMString?

FsmVariables.GetFsmString("example")

all i want to do is essentially create a new variable and change its name and type. Like you would when you manually add a new variable in the FsmEditor.

Nick
Title: Re: Add variable to FSM during edit mode
Post by: coxy17 on December 27, 2017, 03:28:54 AM
bump
Title: Re: Add variable to FSM during edit mode
Post by: Fat Pug Studio on December 27, 2017, 03:40:53 AM
I don't think you can. Make an empty placeholder variable that will be used for transforming it to whatever you need.
Title: Re: Add variable to FSM in edit mode [SOLVED]
Post by: coxy17 on December 28, 2017, 06:00:34 AM
Ok i have found the solution. I can get the variables used by the fsm using the following where 'myfsm' is the fsm you want to target.

Code: [Select]
myfsm.Fsm.Variables
then to get specific types of variables on a FSM I used.

Code: [Select]
myfsm.Fsm.Variables.StringVariables
myfsm.Fsm.Variables.IntVariables
myfsm.Fsm.Variables.BoolVariables
myfsm.Fsm.Variables.GameObjectVariables

After this I added the new variables to these arrays and saved over the old/current values.

Code: [Select]
//make a List from string var
List<FsmArray> list = myfsm.Fsm.Variables.StringVariables.ToList();
//add new value
list.Add("new string");
//save array of string variables back to the fsm
myfsm.Fsm.Variables.StringVariables = list.ToArray();

Then i changed the 'name' of the variable by referencing the index value of the FSM array.
Code: [Select]
myfsm.Fsm.Variables.StringVariables[0].Name = "new string var";
Title: Re: Add variable to FSM during edit mode [SOLVED]
Post by: Fat Pug Studio on December 29, 2017, 06:23:28 AM
Nice solution, great. Do they stay saved upon exiting play mode?
Title: Re: Add variable to FSM during edit mode [SOLVED]
Post by: coxy17 on December 29, 2017, 08:18:05 AM
no sure as im only updating values during edit mode using a EditorWindow custom script. Then update and save just fine, i'll let you know if i test during play mode.
Title: Re: Add variable to FSM during edit mode [SOLVED]
Post by: Fat Pug Studio on December 30, 2017, 11:45:15 AM
Thanks, i'd really like to know.