playMaker

Author Topic: Add variable to FSM during edit mode [SOLVED]  (Read 2405 times)

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Add variable to FSM during edit mode [SOLVED]
« 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
« Last Edit: December 28, 2017, 06:08:41 AM by coxy17 »

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Add variable to FSM during edit mode
« Reply #1 on: December 27, 2017, 03:28:54 AM »
bump

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Add variable to FSM during edit mode
« Reply #2 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.
Available for Playmaker work

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Add variable to FSM in edit mode [SOLVED]
« Reply #3 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";
« Last Edit: December 28, 2017, 06:10:08 AM by coxy17 »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Add variable to FSM during edit mode [SOLVED]
« Reply #4 on: December 29, 2017, 06:23:28 AM »
Nice solution, great. Do they stay saved upon exiting play mode?
Available for Playmaker work

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 355
Re: Add variable to FSM during edit mode [SOLVED]
« Reply #5 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.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Add variable to FSM during edit mode [SOLVED]
« Reply #6 on: December 30, 2017, 11:45:15 AM »
Thanks, i'd really like to know.
Available for Playmaker work