playMaker

Author Topic: String Format Problem  (Read 4442 times)

atmuc

  • Playmaker Newbie
  • *
  • Posts: 26
String Format Problem
« on: August 28, 2013, 03:32:40 AM »
i use {0:F2} as format on Format String Action. it returns full float value like 0.232347284 not 0.32. F2 works on Convert Float To String Action. i also tried {0.00}. do i do something wrong?

atmuc

  • Playmaker Newbie
  • *
  • Posts: 26
Re: String Format Problem
« Reply #1 on: August 28, 2013, 03:42:53 AM »
if i change this line(objectArray = variables.GetValue(); ) it works. is there any reason to send FSMVars to stringFormat?

Code: [Select]
void DoFormatString()
        {
            for (var i = 0; i < variables.Length; i++)
            {
                objectArray[i] = variables[i].GetValue();
            }
           
            try
            {
                storeResult.Value = string.Format(format.Value, objectArray);
            }
            catch (System.FormatException e)
            {
                LogError(e.Message);
                Finish();
            }   
        }

atmuc

  • Playmaker Newbie
  • *
  • Posts: 26
Re: String Format Problem
« Reply #2 on: August 28, 2013, 04:01:20 AM »
FSMVar.GetValue does not work on Action.OnEnter method. even i see float value it return 0 when i call this method inside OnEnter. it works fine in OnUpdate. is it a bug or is it by design?

atmuc

  • Playmaker Newbie
  • *
  • Posts: 26
Re: String Format Problem
« Reply #3 on: August 28, 2013, 04:19:40 AM »
i think i cannot getvalue of named variables onenter method. when i change code like this it works. i changed it just for named float variable.

Code: [Select]
void DoFormatString()
        {
            for (var i = 0; i < variables.Length; i++)
            {
if(variables[i].Type== VariableType.Float)
{
objectArray[i] = ((FsmFloat)(variables[i].NamedVar)).Value;
}
else
                objectArray[i] = variables[i].GetValue();

            }
           
            try
            {
                storeResult.Value = string.Format(format.Value, objectArray);
            }
            catch (System.FormatException e)
            {
                LogError(e.Message);
                Finish();
            }   
        }

atmuc

  • Playmaker Newbie
  • *
  • Posts: 26
Re: String Format Problem
« Reply #4 on: August 29, 2013, 04:17:09 AM »
is it a bug? should i send it to bug report section?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: String Format Problem
« Reply #5 on: September 06, 2013, 10:19:22 AM »
Please submit a bug report and I'll take a look... Thanks!

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: String Format Problem
« Reply #6 on: September 06, 2013, 11:16:09 AM »
I was able to repro. Indeed it should use GetValue(). Good catch!!

However, I wasn't able to repro GetValue failing in OnEnter(). Are you still seeing that?

atmuc

  • Playmaker Newbie
  • *
  • Posts: 26
Re: String Format Problem
« Reply #7 on: September 09, 2013, 03:47:35 PM »
i wrote my own action :-) for now i use it.

PissedOffCil

  • Playmaker Newbie
  • *
  • Posts: 1
Re: String Format Problem
« Reply #8 on: September 20, 2013, 09:27:39 AM »
This works:

Code: [Select]
        void DoFormatString()
        {
            for (var i = 0; i < variables.Length; i++)
            {
if (variables[i].NamedVar != null)
{
variables[i].GetValueFrom(variables[i].NamedVar);
}

                objectArray[i] = variables[i].GetValue();
            }
           
            try
            {
                storeResult.Value = string.Format(format.Value, objectArray);
            }
            catch (System.FormatException e)
            {
                LogError(e.Message);
                Finish();
            }   
        }

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: String Format Problem
« Reply #9 on: September 23, 2013, 02:02:49 AM »
Hi,

 Also, ArrayMaker has a playMakerUtils set of class that feature Fsmvar wrappers to properly get/set them. I use it always when I work with FsmVar, it's doing all the tedious work. AND I am working on a system that can parse var types. for example you pass a string but want a vector 3, that playmakerUtils will let you do that automatically :) more on this in few weeks.

Bye

Jean