Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: justifun on February 24, 2012, 06:36:31 PM
-
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
-
Hi,
First you need to have a reference to the fsm component in your script
declare a public var:
public PlayMakerFSM theFsm;
then you can use:
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:
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
-
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:
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.
-
Sorry, I was doing too much in one line, here how it goes:
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