playMaker

Author Topic: Convert Seconds to string[SOLVED]  (Read 19272 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Convert Seconds to string[SOLVED]
« on: June 06, 2012, 12:01:28 PM »
Hi,

 Following a post: http://hutonggames.com/playmakerforum/index.php?topic=1700.msg7433#msg7433

please find a convenient action that will convert seconds into a formated string to display, days, hours, minutes, seconds, milliseconds, total days, total hours, total minutes, total seconds, total milliseconds.

 It's very easy to use. For example, store the time since level load in a float using the action "get time info" and then inject that float in this action and specify a string variable to output AND the format.

 example:

{1:D2}h:{2:D2}m:{3:D2}s:{4:D3}ms
if the float is 10, it will show: 00h:00m:10s:000ms

{1:D1}:{2:D2}:{3:D2}
if the float is 10, it will show 0:00:10

[EDIT]

I have added a tenth variable that will simply output the milliseconds with two digits, as the current c# formatter do not really allow for a simple way out. the default example is provided with it. Simply inject the "Time since level load" from the action "Get Time info" to see it in action.


careful with the total X values, as they are doubles, so if you want to display the total number of seconds format it like so: {8:F0}

http://stackoverflow.com/questions/463642/c-what-is-the-best-way-to-convert-seconds-into-hourminutessecondsmilliseco

http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx




If you have any questions, don't hesitate

Bye,

 Jean
« Last Edit: October 14, 2013, 03:24:31 AM by jeanfabre »

kiriri

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: Convert Seconds to string
« Reply #1 on: June 06, 2012, 12:13:11 PM »
say one thing, say that I am amazed :D I've never seen that kind of formatting before... definitely need to read up on it ! Awesome  ;D
Best,
Sven

MrMitch

  • Full Member
  • ***
  • Posts: 131
    • View Profile
    • Rage Quit Games - Coming Soon
Re: Convert Seconds to string
« Reply #2 on: June 06, 2012, 02:45:45 PM »
Awesome work, nice flexibility in how you can display the time with : . etc :)

Thanks again Jean :)

alternativee30

  • Playmaker Newbie
  • *
  • Posts: 24
    • View Profile
Re: Convert Seconds to string
« Reply #3 on: July 08, 2012, 06:01:38 PM »
How would one go about doing the reverse of this action? Convert Time formatted String into Seconds?

simon8029

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Convert Seconds to string
« Reply #4 on: April 30, 2013, 07:23:44 AM »
if i set the format like this: {1:D2}h:{2:D2}m:{3:D2}s:{4:D1}ms,
it does not display like this: 00h:00m:00s:0ms but like this:00h:00m:00s:000ms.

How to set ms correctly? help pls.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Convert Seconds to string
« Reply #5 on: May 02, 2013, 11:11:10 AM »
Hi,

 works for me. could you give me the actual float you are using on that action?

[EDIT] my bad I checked with a real number, and I see the problem.

 let say your milliseconds value is 100, D1 will still output 100, because it only asks for minimum 1, not cut it to 1.


D5 will ouput 00100

do you get it? I don't think there is a way to get out of this using this action, since it's a built in feature of c#...

 the way to go about it, would be to parse the milliseconds yourself and compose the string later, so only use this action without the ms, then add the ms you want ( still using this action, but ONLY get the ms using {4:} as a formater, then cut the string and compose it using build string action.

 Does that make sense?

bye,

 Jean
« Last Edit: October 02, 2013, 11:45:01 PM by jeanfabre »

simon8029

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Convert Seconds to string
« Reply #6 on: May 04, 2013, 09:01:04 AM »
Yes it does, thanks a lot! :)

Pawel

  • Junior Playmaker
  • **
  • Posts: 93
    • View Profile
Re: Convert Seconds to string
« Reply #7 on: August 02, 2013, 07:09:55 AM »
I run into a bug here: This action kills any other string conversion -- for example if you have a separate time and score running at the same time...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Convert Seconds to string
« Reply #8 on: August 05, 2013, 12:42:11 AM »
Hi,

 I am not sure I follow. Can you explain a bit more? this action in theory is complitly self contained, so it can not affect other variables then the one explicitly referenced in that action.

bye,

 Jean

Pawel

  • Junior Playmaker
  • **
  • Posts: 93
    • View Profile
Re: Convert Seconds to string
« Reply #9 on: August 07, 2013, 02:12:12 PM »
Sorry for the delay...

I had two items that wanted to show on the screen -- the time since the level start and the score points. I used Convert Int to String to show the score and Convert Seconds to String to show the time. Both work ok when only one is active, but when both are on the screen at the same time one of them no longer works...

Now, there is no problem if I run both the score and time together if I use Convert Float to String to display the time -- only Convert Seconds to String gives me the trouble.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Convert Seconds to string
« Reply #10 on: August 08, 2013, 12:52:34 AM »
Hi,

 it's likely in your logic that you mix up values and tasks. Separate your logic in two fsm, that's how I would approach solcing this.

what trouble do you have with convert seconds to string? could you give me an example of your input and what you end up with?

bye,

Jean

Pawel

  • Junior Playmaker
  • **
  • Posts: 93
    • View Profile
Re: Convert Seconds to string
« Reply #11 on: August 08, 2013, 11:16:49 AM »
As usual you are right Jean! Honestly I am not even sure what was wrong, since I  no longer have it setup the same way but when I tried both time and score running together -- there was no problem... Both are running at the same time.

My guess is that the use of global variables was the cause... Is this what the bug fix was about?

aLDime

  • Playmaker Newbie
  • *
  • Posts: 24
    • View Profile
    • http://aldimegame.com/
Re: Convert Seconds to string
« Reply #12 on: October 01, 2013, 01:21:49 AM »
then cut the string and compose it using build string action.

Hi,
Thanks a lot for this action!
But need format time -  00m:00s:00ms!
How can "cut the string" via PlayMaker Action?
« Last Edit: October 01, 2013, 01:28:14 AM by aLDime »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Convert Seconds to string[SOLVED]
« Reply #13 on: October 03, 2013, 12:41:23 AM »
Hi,

 I have added this function within the action ( simply redownload it again from this thread)

 {1:D2}h:{2:D2}m:{3:D2}s:{10}ms

will do the job.

 Bye.

 Jean

aLDime

  • Playmaker Newbie
  • *
  • Posts: 24
    • View Profile
    • http://aldimegame.com/
Re: Convert Seconds to string Bug?
« Reply #14 on: October 03, 2013, 01:39:47 AM »
Hi,

Wow, amazing, great!
I am sure what who make race as I am, this will be necessary as air!

Thanks much Jean!
« Last Edit: October 14, 2013, 02:23:12 AM by aLDime »