Lavishscript Decimal Time to Real Time Conversion

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
bjcasey
GamingTools Subscriber
Posts: 8
Joined: Wed Jun 27, 2007 8:56 am

Lavishscript Decimal Time to Real Time Conversion

Post by bjcasey » Sun Feb 12, 2012 2:12 pm

Hello,

In my script I am displaying the running time on a UI and have it formatted to MMMM:SS.

Code Snip Below:

Code: Select all

[${Math.Calc[(${Script[scriptname].RunningTime}/1000)/60].Centi}]
I would like for it to be formatted instead in real time like HH:MM:SS. How would I go about making this conversion or am I out of luck?

Thanks!

bjcasey
GamingTools Subscriber
Posts: 8
Joined: Wed Jun 27, 2007 8:56 am

Post by bjcasey » Sun Feb 12, 2012 2:33 pm

Went on IRC and got some help.

Code: Select all

[14:23]	Lax	first get the number of seconds by dividing by 1000
[14:23]	Lax	displaySeconds = TotalSeconds%60
[14:24]	Lax	TotalSeconds/=60
[14:24]	Lax	or TotalMinutes= TotalSeconds/60
[14:24]	Lax	displayMinutes = TotalMinutes/60
[14:24]	Lax	%60
[14:24]	bjcasey	[${Math.Calc[(${Script[scriptname].RunningTime}/1000)/60].Centi}]
[14:25]	Lax	you're on the right track. you'll need to keep variables and use both /60 and %60
[14:27]	bjcasey	ok thanks. what does the %60 part do and what does the / do for TotalSeconds
[14:29]	Lax	% is modulo operator
[14:29]	Lax	if it's been running for 123 seconds
[14:29]	Lax	you're going to want to display 2 minutes 3 seconds
[14:29]	Lax	if you just divide by 60, you are going to get 2
[14:30]	Lax	to get the 3 you can either subtract 2*60 from your total
[14:30]	Lax	or you can modulo the total seconds by 60
[14:30]	Lax	because you know that's going to be the number to put in SS
[14:30]	bjcasey	oh cool, thanks
[14:31]	Lax	then you calculate the total number of minutes, and modulo 60 again because you want hours
[14:31]	Lax	in the next slot
[14:31]	Lax	and totalminutes%60 is the number to put in MM
[14:31]	Lax	repeat for however many extra places you want. days ec
[14:32]	Lax	etc*

Post Reply