Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: MUX on February 26, 2013, 08:51:56 AM
-
Hey Forum!
i have a tiny dilemma with game-center results formatting when it comes to 'Comma Separated Thousands'.. what would be the best way to separate a string 123456789 to 123,456,789 ? was thinking about using something like http://msdn.microsoft.com/en-us/library/0c899ak8%28v=VS.90%29.aspx#SpecifierTh but with no luck . would i have to count backwards from the end? use an int instead? need it to support shorter values like 1234 to 1,234 too.
heres how i tried..
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Custom)]
[Tooltip("splits string in comma thousands")]
public class StringCommasAdd : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmString StringVariable;
[RequiredField]
public bool everyFrame;
public override void Reset()
{
StringVariable = null;
everyFrame = false;
}
public override void OnEnter()
{
double value = StringVariable.Value;
value.ToString("#,#", CultureInfo.InvariantCulture);
StringVariable.Value=value.ToString("#,#", CultureInfo.InvariantCulture);
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
double value = StringVariable.Value;//1234567890;
value.ToString("#,#", CultureInfo.InvariantCulture);
StringVariable.Value=value.ToString("#,#", CultureInfo.InvariantCulture);
}
}
}
are the .net functions available in custom actions? hope someone can help
thanks
-
Hi,
There's nothing out of the box, nor any actions in playmaker to deal with this, but it's doable, Have a look at the following links:
http://msdn.microsoft.com/en-us/library/xbtzcc4w.aspx
http://msdn.microsoft.com/en-us/library/3s27fasw.aspx
http://msdn.microsoft.com/en-us/library/xbtzcc4w(v=vs.71).aspx
you seem to be ok with c#, but if you need a custom action, let me know.
bye,
Jean
-
thanks jean, still struggling with this unfortunately. would appreciate if you have the the time or maybe some 1-on-1. once again, thanks for your help!
-
its a long winded way around it but you could do a compare and set the int to string formating option.
example, if number 'A' = > 999 then set formating as 0,000
if 'A' = > 999999 then formating is 0,000,000
if jean comes up with an action it would probably be better for performance and keeping stuff clean but the above should work.
sometimes I have to make work arounds to problems when I am unsure of how to fix them properly.
-
yup Sjones.. that's exactly how i hacked prime31 to work with NGUI in reverse
_ScoreCount = scores[0].ToString();
string[] ValuesToSplit = _ScoreCount.Split(',');
float arraycount = 0;
foreach (string values in ValuesToSplit)
{
Debug.Log("values :"+values);
arraycount++;
}
Debug.Log("arraycount value :::"+arraycount);
Debug.Log("Values To Split Length :"+ValuesToSplit.Length);
if(arraycount==8){
Debug.Log("HIGH :: XXX,XXX,XXX arraycount value :::"+arraycount);
//
Debug.Log("scoresLoaded _ScoreCount :"+ValuesToSplit);
_ScoreCount = ValuesToSplit[7].ToString();
_ScoreCount = _ScoreCount.Substring(11);
Debug.Log("scoresLoaded _ScoreCount Final :"+_ScoreCount);
//
} else if(arraycount==7){
Debug.Log("MID :: XXX,XXX arraycount value :::"+arraycount);
//
Debug.Log("scoresLoaded _ScoreCount :"+ValuesToSplit);
_ScoreCount = ValuesToSplit[6].ToString();
_ScoreCount = _ScoreCount.Substring(11);
Debug.Log("scoresLoaded _ScoreCount Final :"+_ScoreCount);
//
} if(arraycount==6){
Debug.Log("LOW :: XXX arraycount value :::"+arraycount);
Debug.Log("scoresLoaded _ScoreCount :"+ValuesToSplit);
_ScoreCount = ValuesToSplit[5].ToString();
_ScoreCount = _ScoreCount.Substring(11);
Debug.Log("scoresLoaded _ScoreCount Final :"+_ScoreCount);
//
}
so just wanna find a tidy way to do it with playmaker action , but backwards.
struggling!