playMaker

Author Topic: Sending a variable from a custom script back to playmaker [SOLVED]  (Read 18793 times)

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
I see how to send a variable from a FSM to a custom script, but how do you send a variable from within a script back to an FSM?

for example, i have a script that reads the text from a text file and stores it as a string.  how do i get playmaker to pick that up?

thx
« Last Edit: February 29, 2012, 01:22:36 PM by Alex Chouls »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sending a variable from a custom script back to playmaker
« Reply #1 on: February 27, 2012, 03:06:41 AM »
Hi,

 First you need to have a reference to the fsm component in your script

declare a public var:

Code: [Select]
public PlayMakerFSM theFsm;

then you can use:

Code: [Select]
theFsm.FsmVariables.GetFsmBool("My bool var").Value = false;

If you have more than one fsm component attached to your gameObject, It can become confusing so I suggest another approach to the public var. Instead, reference the name of the fsm you want to access and use in the awake the following script:

Code: [Select]

PlayMakerFSM[] temp = GetComponents<PlayMakerFSM>();
foreach (PlayMakerFSM fsm in temp) {
if (fsm.FsmName == "the fsm I want to work with"){
theFsm = fsm;
break;
}
}

This would be the basic approach.

Hope this helps,

Bye,

 Jean

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Sending a variable from a custom script back to playmaker
« Reply #2 on: February 27, 2012, 11:34:27 AM »
Sorry Jean i'm still confused.

The part where you say theFsm.FsmVariables.GetFsmBool("My bool var").Value = false;

Isn't that simply reading the variable ("my bool var") value from the FSM ?

I want send a variable from a custom script so that the fsm can pick it up and use it.

For example here's a line from my code

var text : String = System.IO.File.ReadAllText("C:\\testread.txt");

How do i pass the variable "text" back?

Is there such a thing as "SetFSMString"?

EG:
Code: [Select]
public PlayMakerFSM theFsm;
var text : String = System.IO.File.ReadAllText("C:\\testread.txt");
theFsm.FsmVariables.SetFsmString("my text string").Value = text;

thx for your help.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sending a variable from a custom script back to playmaker
« Reply #3 on: February 27, 2012, 02:17:10 PM »
Sorry, I was doing too much in one line, here how it goes:

Code: [Select]
FsmString myFsmString = theFsm.FsmVariables.GetFsmString("My string var");


myFsmString.Value = "Hello";


GetFsmBool() actually return the Fsm variable, not that value it contains, the value it contains is then accessed by .Value, that you can set or get.

Hope this is clearer now :)

 Bye,

 Jean