playMaker

Author Topic: How Do I Get an FSM Variable from inside a script  (Read 2687 times)

rickmiranda

  • Playmaker Newbie
  • *
  • Posts: 11
How Do I Get an FSM Variable from inside a script
« on: September 03, 2013, 07:02:28 PM »
Hi

I'm implementing the following:
-----------------------------------------
#pragma strict
var delta : float = 10 * Time.deltaTime;
var position_new : float;
var position_current : float;

function Start () {
}

function Update () {
delta = 10 * Time.deltaTime;
//var position_current : float = transform.position.y;
position_current = transform.position.y;

Debug.Log("delta:"+delta);
Debug.Log("Platform Position: "+position_current);
transform.Translate(Vector3.down * Time.deltaTime*15, Space.World);

   if (transform.position.y<-34.9999999)
   {
   position_new = position_current - Time.deltaTime*100 + 148;
   transform.position = new Vector3(65, position_new , 1);
   }

}
-----------------------------
I also have a separate empty Object that updates some variables for me.
The empty Object updates the position of a GameObject in the scene.

I would like to know how I can access the GameObject's position, or the emptyObjects variable (either or), from inside the script described above....

I think I've seen that I have to put in "using Playmaker.Plugin..." or something but...any help will be great...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How Do I Get an FSM Variable from inside a script
« Reply #1 on: September 11, 2013, 05:08:46 AM »
Hi,

 do the following:

Code: [Select]

// WARNING: this is not efficient, but shows the process. Instead prefer declaring a public variable or type PlayMakerFSM and drop the fsm component in question.
var fsmObject : PlayMakerFSM = gameObject.FindWithTag("AnyFSM").GetComponent.<PlayMakerFSM>();

var currentValue : float = fsmObject.FsmVariables.GetFSMFloat("value").Value + amount;

fsmObject.FsmVariables.GetFSMFloat("value").Value = currentValue;

Does that help?

 Bye,

 Jean