playMaker

Author Topic: Create fsm var at runtime?  (Read 1846 times)

Pawl

  • Playmaker Newbie
  • *
  • Posts: 8
Create fsm var at runtime?
« on: August 19, 2014, 01:25:18 PM »
Hello, I've created a custom FsmStateAction which currently looks for an existing fsm variable via:

Code: [Select]
var reset = Fsm.GetFsmBool("IsReset");
but I was wondering if it would be possible to create the fsm variable and add it to the state machine at runtime if it doesn't already exist?

I didn't see any public methods to add new vars, however I did see there is access to:

Code: [Select]
Fsm.Variables.BoolVariables;
from within an FsmStateAction, but I'm wondering if it's safe to modify that at runtime?

Thanks!! Paul

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Create fsm var at runtime?
« Reply #1 on: October 15, 2014, 01:28:46 AM »
Hi,

 there is no use case for this as far as I am aware, since you have to design your fsm during editing, adding a fsmvar at runtime can not be then used or wired to any actions since you can't edit fsm at runtime ( you will loose changes as you stop playing).

 can you explain what you are after?

 Bye,

 Jean

Abelius

  • Junior Playmaker
  • **
  • Posts: 68
Re: Create fsm var at runtime?
« Reply #2 on: January 22, 2021, 02:15:03 PM »
Hello there.

I'm going to highjack and necro this thread at the same time, because it's the first result that shows when searching for this in Google.

there is no use case for this as far as I am aware

I can think of one, at least.

I don't know if at the time of this post the action "Set FSM Variable" existed or not, but you can pass a string variable to the var name...:



And if you can do that, you can also use that string to reference that variable, at a later time, with the action "Get FSM Variable".

Now, when I saw these two actions I kind of took for granted "Set FSM Variable" would create a local FSM variable on it own, in case it doesn't find a premade one... but that's not the case. It throws an "not found" error instead.

In my case, I was going to use that feature inside loops, to create temporary debugging variables. So yeah, it would be nice if a new one would be created.

I understand you could argue that's not useful enough, or that this can be made in other ways (as it always is the case in coding), but I think this would be a nice option to have, regardless.

Would it be possible to modify the Set action so it creates a new local FSM var? Is this possible at all?

Thanks.
Unity 2019.4.9f1
Playmaker 1.9.7f1