playMaker

Author Topic: Displaying 1000 as 1,000, and converting seconds to minutes [SOLVED]  (Read 3006 times)

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Hi,
Is there any actions that do this? I did a search but couldn't see anything.

I have a timer that counts how long the player survived in seconds, which I'd like to convert to mins/secs and also my score gets rather huge (over 1 million) and I'd like commas so its displayed 1,000,000.

Do I need to create an entire state machine just to convert seconds to minutes and rebuild the string? I'm not sure how I'd deal with remainders and so on after dividing for minutes. Same question for the large numbers, would I have to create an FSM to divide by 1000, save as string, rebuild, etc? Embarrassing isn't it? :/

Thanks for any help!
Regards,
Jay
« Last Edit: September 21, 2012, 08:00:36 AM by jayhfd »

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Displaying 1000 as 1,000, and converting seconds to minutes
« Reply #1 on: September 20, 2012, 03:55:52 PM »
What you're talking about is called string formatting. http://hutonggames.com/playmakerforum/index.php?topic=1711.0#lastPost

Now, there's probably another action for the million thingy, but I'd like to show you the universal way to handle such stuff with simple actions only.
Say your highscore counts up from 0. Each time you add 1 or more points, you can check if n (number so far) is greater than 1000. If it is, you subtract 1000 from n and add one to p. That p is then the equivalent of 1000. Later you build your string and say for example it's 3 parts long: 1) p 2), 3)n. And there you go, then it should show up as 1,000 . Now, while these actions don't really use much they won't hit your performance, even if looped. However, formatting is especially in the case of a large and changing thing such as a highscore be the very much better solution :P
But oh well :D Hope you can use that technique anyways sometime.
Best,
Sven

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Displaying 1000 as 1,000, and converting seconds to minutes
« Reply #2 on: September 21, 2012, 01:27:11 AM »
Hi,

 you should investigate the use of c# string format system.

http://hutonggames.com/playmakerforum/index.php?topic=267.0
check the link he's providing, it has numerous examples that I am sure will help you with your 1,000 type of format

 as for seconds to minutes convertion. These threads might be helping too:
http://hutonggames.com/playmakerforum/index.php?topic=1711.0
http://hutonggames.com/playmakerforum/index.php?topic=1047.0

bye,

 Jean

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Re: Displaying 1000 as 1,000, and converting seconds to minutes [SOLVED]
« Reply #3 on: September 21, 2012, 08:02:19 AM »
Great stuff, thanks guys, that was quick and easy!

I would suggest for the help tooltip thing, that you add a couple of simple examples, and maybe a link to all the different formatting options. I was under the impression that the only thing that format did was add those 0000's to the front! :)

Thanks!
Jay