playMaker

Author Topic: How to pass String Variable to Script from FSM  (Read 2277 times)

geoquav

  • Playmaker Newbie
  • *
  • Posts: 14
    • View Profile
How to pass String Variable to Script from FSM
« on: April 25, 2013, 08:04:01 AM »
I am hitting a brick wall here and am unsure of why. I am currently trying to pass a String variable from one of my FSMs to a Script. I am thus far unable to do so.

I have read the following threads:
http://hutonggames.com/playmakerforum/index.php?topic=2429.0
http://hutonggames.com/playmakerforum/index.php?topic=1759.0
http://hutonggames.com/playmakerforum/index.php?topic=1143.0
http://hutonggames.com/playmakerforum/index.php?topic=606.0
http://hutonggames.com/playmakerforum/index.php?topic=95.0

And am still unable to figure out what I am doing wrong. Here is my current code:
Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;

public class PostHighScore : MonoBehaviour
{
string stringName = null;
string stringScore = null;
public PlayMakerFSM myFSM;

void Start ()
{
}

void Update ()
{
}

void getName(FsmString stringA)//attempt 1
{
stringA.Value = stringName;
}

void setName()//attempt 2
{
stringName = myFSM.FsmVariables.GetFsmString("Name").Value ;
}

void getScore(string stringA)//attempt 3
{
stringA = stringScore;
}
}

As you can see I have tried three separate methods and none have worked for me. Let me know if you guys see any mistakes on my end or something that I am missing. Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15093
  • Official Playmaker Support
    • View Profile
Re: How to pass String Variable to Script from FSM
« Reply #1 on: April 25, 2013, 11:31:37 AM »
Hi,

 attempt 3 will do nothing with playmaker fsm, so you can pass that

attempt 2 will work only IF there is a indeed an Fsm string variable called "name" in myFSM

attempt 1 will work too.

Now, your problem might be outside this class. Could you share a sample?

also, is it not a case where your fsm string variable is empty when you check... that happens to me a lot...

bye,

 Jean

geoquav

  • Playmaker Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to pass String Variable to Script from FSM
« Reply #2 on: April 25, 2013, 12:22:14 PM »
For #2 there is an FSM string variable named Name (not sure if case sensitive). It is already pre-populated so it shouldn't be blank.

#1 does not show up as an option to choose under Method. I can type it in manually though. Once again the variable is pre-populated so it shouldn't be the problem here.

Here is the scenario:
I recently purchased a Leaderboard Addon to integrate a leaderboard into my game. I am unable to use the "Send Message" action because it requires more than one field. So my thinking was to add a script which contained the actions I wanted to perform and to pass through my variables from the FSM to the Script and then populate it with those to run it. (If you see flaws in this logic I am open to suggestions).

Here is the script I have attached to my GameObject that I am making calls to:

Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;

public class PostHighScore : MonoBehaviour
{
public string stringName = null;
public string stringScore = null;

private iXHighScoreBinding hs;
public PlayMakerFSM myFSM;

// Use this for initialization
void Start ()
{
hs = (iXHighScoreBinding) GameObject.FindObjectOfType(typeof(iXHighScoreBinding));
}

// Update is called once per frame
void Update ()
{

}

void createName()
{
StartCoroutine(hs.postPlayerName(stringName, "idIPhone", "lg", 1));
}

void callPostScore()
{
StartCoroutine(hs.postPlayerScore(stringName,stringScore,"1"));
}

void getName(FsmString stringA)//#1
{
stringA.Value = stringName;
}

void setName()//#2
{
stringName = myFSM.FsmVariables.GetFsmString("Name").Value;
}
}

The actions are performed in this order:
1. Get/Set Name (Whichever works)
2. Create Name

So they should be getting populated. I have verified the actions work because null is being uploaded to my SQL DB which is populated above. If you need anymore information let me know.

Thanks for the help Jean.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15093
  • Official Playmaker Support
    • View Profile
Re: How to pass String Variable to Script from FSM
« Reply #3 on: April 29, 2013, 12:03:10 PM »
Hi,

 from what I can see here, the possible and likely failure is that "startCoroutine" is asynchrone, which means you MUST implement a way for your leaderboard system to call you back and validate your initial call (set the name or post a score), else you are likely querying for the name too soon.

 Could this be the case? in terms of code, this is fine ( from what I can see), so I am pretty sure your problem lie somewhere else, more ont he logic and "sequential" pattern that your coroutine call breaks.

bye,

 Jean