Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on June 06, 2012, 12:01:28 PM

Title: Convert Seconds to string[SOLVED]
Post by: jeanfabre on June 06, 2012, 12:01:28 PM
Hi,

 Following a post: http://hutonggames.com/playmakerforum/index.php?topic=1700.msg7433#msg7433 (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://stackoverflow.com/questions/463642/c-what-is-the-best-way-to-convert-seconds-into-hourminutessecondsmilliseco)

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




If you have any questions, don't hesitate

Bye,

 Jean
Title: Re: Convert Seconds to string
Post by: kiriri 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
Title: Re: Convert Seconds to string
Post by: MrMitch on June 06, 2012, 02:45:45 PM
Awesome work, nice flexibility in how you can display the time with : . etc :)

Thanks again Jean :)
Title: Re: Convert Seconds to string
Post by: alternativee30 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?
Title: Re: Convert Seconds to string
Post by: simon8029 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.
Title: Re: Convert Seconds to string
Post by: jeanfabre 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
Title: Re: Convert Seconds to string
Post by: simon8029 on May 04, 2013, 09:01:04 AM
Yes it does, thanks a lot! :)
Title: Re: Convert Seconds to string
Post by: Pawel 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...
Title: Re: Convert Seconds to string
Post by: jeanfabre 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
Title: Re: Convert Seconds to string
Post by: Pawel 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.
Title: Re: Convert Seconds to string
Post by: jeanfabre 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
Title: Re: Convert Seconds to string
Post by: Pawel 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?
Title: Re: Convert Seconds to string
Post by: aLDime 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?
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre 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
Title: Re: Convert Seconds to string Bug?
Post by: aLDime 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!
Title: Re: Convert Seconds to string Bug?
Post by: aLDime on October 14, 2013, 02:22:27 AM
Hi,
Please see the screenshots, it's a bug or am I doing something wrong?)
If Float is 2.099 **** time is 00:02:99, next step (on paused)
Float is equal 2.103, ***, time returned 00:02:10, but should be 00:03:10
Of course this fatal error for the races ...
Quite urgently need your help!
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on October 14, 2013, 03:18:57 AM
Hi,

 Nice catch! Quite tricky actually... Can you redownload the action and see if it works. I tested with your numbers and it works.

bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: aLDime on October 14, 2013, 04:58:06 AM
Hi,
I thought about this problem for over a week, and could not understand what was happening, all day yesterday I caught this bug :-/
I did some quick tests, so far so good and I not catched this bug again, I'll be more tested over 2-3 days, and I'll write result here. Thanks for the quick response and help!
Title: Re: Convert Seconds to string[SOLVED]
Post by: aLDime on October 19, 2013, 09:58:22 PM
Made more than 100 tests, everything works fine! Min, sec, ms, rest I don't need ;) Thank you so much, Jean!
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on October 20, 2013, 11:52:32 PM
Good. Thanks for the update!

bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: aLDime on November 12, 2013, 04:57:17 AM
Hi,
have spikes in debugging, the frequency I can not determine, but in ~1.5 minutes 4-5 to 20-28ms spikes
Title: Re: Convert Seconds to string[SOLVED]
Post by: aLDime on November 12, 2013, 05:57:29 AM
test in empty project spike is less
~ 4-5ms
but it's still very high ...
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on November 12, 2013, 06:09:21 AM
Hi,

 you are fine, you are running at >100FPS! Profiling only become relevant if you go below 60FPS.

 bye,

 Jean
Title: Re: Convert Seconds to string
Post by: aLDime on November 12, 2013, 06:16:21 AM
hmm, I have friezes in game for that reason, if I disable timer, friezes no ... you think this is normal?
Title: Re: Convert Seconds to string
Post by: aLDime on November 12, 2013, 07:53:56 AM
All that more than 3-4 ms on game - is not clean code! and I have a spike in the game reaches more than 20ms - this less than 60FPS
Title: Re: Convert Seconds to string[SOLVED]
Post by: escpodgames on November 13, 2013, 10:00:46 PM
Hey Jean,

How would you reverse this action so it would count down from a value ie 10 mins/ 600 secs?
Title: Re: Convert Seconds to string
Post by: jeanfabre on November 13, 2013, 10:13:43 PM
Hi,

All that more than 3-4 ms on game - is not clean code! and I have a spike in the game reaches more than 20ms - this less than 60FPS

Yep, something is fishy here indeed. I have added this case to my todos, and I'll run some stress test to see where the problems lies. Can you come back to me next week if you haven't heard back from me?

 
Bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on November 13, 2013, 10:15:27 PM
Hi,

How would you reverse this action so it would count down from a value ie 10 mins/ 600 secs?

This action only converts what you give it, so if you want to count down you simply have the float substracted instead of added and passe that to this action, unless I misunderstand what you are trying to achieve.

bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: escpodgames on November 13, 2013, 10:17:42 PM
Thx, that makes perfect sense. :)
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on July 16, 2014, 05:18:35 AM
Hi,

 You can now find this action on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181) for convenience.

 Bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: blackant on October 25, 2014, 12:10:31 PM
Hello,

i cannot find this action on ecosystem..
but well, trying to use the one linked on others post,
i have a problem to set the format of the time, see the screenshot....
Title: Re: Convert Seconds to string[SOLVED]
Post by: escpodgames on October 25, 2014, 03:24:52 PM
It's on there - search 'time'

also your formating looks correct .. not sure what is going on there :S
Title: Re: Convert Seconds to string[SOLVED]
Post by: blackant on October 27, 2014, 12:22:22 AM
it works correctly if i use format 00:00:00
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on November 26, 2014, 11:35:14 PM
Hi,

 Yeah, I can confirm it's on the ecosystem, search for "convert seconds".

Bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: djaydino on December 02, 2014, 06:15:24 AM
Hey Jean,

How would you reverse this action so it would count down from a value ie 10 mins/ 600 secs?

Try This (http://hutonggames.com/playmakerforum/index.php?topic=8831.0)
Title: Re: Convert Seconds to string[SOLVED]
Post by: Rabagast on November 19, 2015, 08:04:53 AM
Hi,

 Following a post: http://hutonggames.com/playmakerforum/index.php?topic=1700.msg7433#msg7433 (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://stackoverflow.com/questions/463642/c-what-is-the-best-way-to-convert-seconds-into-hourminutessecondsmilliseco)

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




If you have any questions, don't hesitate

Bye,

 Jean


Hi!
Why doesn't this second to string allow me to count the miliseconds (MS) like 101,102,103,104, etc. or 10,11,12,13,14,15, etc.? It's counting only: 100,200,300,400,500, etc.

Is this not possible? Should be. I have seen it in other games! :)
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on November 22, 2015, 11:18:30 PM
Hi,

 What is the exact string format are you using?

Bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: Rabagast on November 26, 2015, 04:21:35 AM
Hi!
Thanks for the answer! :)

I use this format: {2:D2}:{3:D2}:{10}
And it counts like this: 00m:00s:00ms
I want ms to be like: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Not 00, 10, 20, 30, 40, 50, 60, 70, 80, 90
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on December 01, 2015, 04:19:09 AM
Hi,

simply use "{1:D1}h:{2:D1}m:{3:D1}s:{4:D3}ms"

and you'll get:

(http://i.imgur.com/gvWGUT0.png)

your format is wrong for the ms, {10} isn't right.

 Bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: Rabagast on December 04, 2015, 06:18:28 AM
Ok!
But the format is still not what I want! I want this:
00:00:0 not 00:00:000

I deleted hour since I'm not going to have that.

I tried to set it up like this: {2:D1}:{3:D1}:{4:D1}, since I don't want to have the two zero at the end, but it's still counting like this: 00:00:100, 00:00:200, 00:00:300, etc.

Is it not possible? Or is it possible to update the Action so it will be possible?

Another thing maybe I do wrong is the Wait Action! The first state I have Wait 0.1.
The next state I have:
-Float Add 0.1
-Convert Seconds To String
-U Gui Set Text

I see in the screenshot that it is 058 ms. I don't get that
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on December 05, 2015, 05:03:51 AM
Hi,

 I see... indeed if you wait a 0.1 seconds you'll only get times with this accuracy :) this is logical

 The action is using the standard c# .net format, so there is no other way using this method.

when you have such issues, starts with a clean scene, one gameobject, one fsm, one state, one action, study how it works and then you can apply it back to your real environment. Typically, you'll find that this action has it's ms properly working, but indeed within your system, since you wait 0.1 everytime you parse, you won't get more precise by definition of your logic.

 Bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: Rabagast on December 07, 2015, 11:09:02 AM
Hi!

I also tried to use Float Interpolate on the ms, so the ms will use 1 second to reach 1000 or 100 or 10 and then I add 1 to the second. I got it to work in this way. The only problem I got was not the timer itself, but when I use Easy Save to save the time. It was a problem when I got a new best time, since I use Convert Seconds To String on minutes and seconds and ms is separated. I use Float Compare to check if the current time is higher than the best time. And here is the problem since min. and sec. are in one variable and ms is in another variable.

Hope you understand me! It was a little bit difficult to explain. :)
Title: Re: Convert Seconds to string[SOLVED]
Post by: Rabagast on December 12, 2015, 05:15:26 PM
Jean:
I got it to work! I didn't use "Convert Seconds To String" I use "Float Interpolate", and seconds and milliseconds separated! I had to do everything manually! I can show a video of how it works! :)
Title: Re: Convert Seconds to string[SOLVED]
Post by: Rabagast on December 14, 2015, 01:31:15 AM
I created a new topic with a link of the video of the Game Time!

http://hutonggames.com/playmakerforum/index.php?topic=11833.0 (http://hutonggames.com/playmakerforum/index.php?topic=11833.0)

Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on December 14, 2015, 03:59:35 AM
Hi,

 Nice, I am glad you got it working!

 I think I understand now what you are looking for that the string format doens't provide. I'll see if I can get an update on the action to feature this.

 Bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: Rabagast on December 14, 2015, 05:32:26 AM
Hi, Jean!

Yes, that would be great, it would be easer, but I'm very happy and a little bit proud with my Game Time setup. :)
Title: Re: Convert Seconds to string[SOLVED]
Post by: jeanfabre on December 16, 2015, 01:26:02 AM
Hi,

 Indeed, this is great that you got it working by yourself, this is the best way to get better and learn PlayMaker inside out.

 Bye,

 Jean
Title: Re: Convert Seconds to string[SOLVED]
Post by: Rabagast on December 16, 2015, 03:10:26 AM
If someone is interested, I can share my game time setup! :)
Title: Re: Convert Seconds to string[SOLVED]
Post by: Rabagast on December 16, 2015, 01:46:04 PM
I upload my Game Time Setup!

You can find it here! :)

http://hutonggames.com/playmakerforum/index.php?topic=11865.0 (http://hutonggames.com/playmakerforum/index.php?topic=11865.0)
Title: Re: Convert Seconds to string[SOLVED]
Post by: pampapic on November 01, 2016, 03:45:15 AM
Hi, this action is not available anymore in Ecosystem?
Title: Re: Convert Seconds to string[SOLVED]
Post by: djaydino on November 01, 2016, 06:01:52 AM
Hi,
This action is available in the default actions list