playMaker

Author Topic: Access FSM variable in scrip and vice versa  (Read 2579 times)

TifaOng

  • Playmaker Newbie
  • *
  • Posts: 10
Access FSM variable in scrip and vice versa
« on: December 02, 2013, 11:29:17 PM »
I have a question.

If I have a bool variable in FSM, how do I access this variable in an existing script? and vice versa.

Same thing, I have script variables, how to access in FSM?

Thanks in advance!

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Access FSM variable in scrip and vice versa
« Reply #1 on: December 03, 2013, 03:34:40 AM »
Hi,

Script -> Playmaker:
Code: [Select]
var fsm = GetComponent<PlayMakerFSM>();
if (fsm != null) {
FsmBool mybool = fsm.FsmVariables.FindFsmBool("MyBool");
if (mybool != null) {
bool myBoolValue = mybool.Value;
}
}

Be aware of the difference between "FindFsmXY" and "GetFsmXY", the first returns null if not found and the later returns a new default variable with the given name, means it cant fail.


Playmaker -> Script:
Use the "GetProperty" Action for easy access,  this should work on any public fields or properties.


bye Andy

TifaOng

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Access FSM variable in scrip and vice versa
« Reply #2 on: December 03, 2013, 08:39:44 PM »
From Script -> PlayMaker, this means I need to have PlayMakerFSM class?
Like HutongGames.PlayMaker.PlayMakerFSM : UnityEngine.MonoBehaviour ?

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Access FSM variable in scrip and vice versa
« Reply #3 on: December 04, 2013, 07:04:57 AM »
From Script -> PlayMaker, this means I need to have PlayMakerFSM class?
Like HutongGames.PlayMaker.PlayMakerFSM : UnityEngine.MonoBehaviour ?

No u don't need to derive a new class, u just import the namespace by:
Code: [Select]
using HutongGames.PlayMaker; in your script and then u get/use the FSM component reference.

bye Andy