Converting Seconds to Minutes

Post Reply
robm06
Posts: 14
Joined: Fri Jun 11, 2010 1:02 am

Converting Seconds to Minutes

Post by robm06 »

Well,

Now that I fixed my last problem, I'm stumped on something new (surprise?)

Anyways, I'm wanting to take a number 40 for instance, and do math magic on it to get seconds and then convert the seconds to a minutes display of minutes:seconds remaining.

The only thing I could get was a readout like 13.6 after multiplying it, but after I get 13.6 I want to take the decimal and get seconds from that.

Any idea?
Sorry to be a pain

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Converting Seconds to Minutes

Post by Denarii »

What are you converting to seconds?

robm06
Posts: 14
Joined: Fri Jun 11, 2010 1:02 am

Re: Converting Seconds to Minutes

Post by robm06 »

Denarii wrote:What are you converting to seconds?
Something in the game ticks 40 times, 20 seconds apart. I'm wanting to make a conversion to countdown based on how many ticks are left.

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Converting Seconds to Minutes

Post by Denarii »

Code: [show] | [select all] lua
ticktimer = createStopWatch()
When the ticking starts, do:
Code: [show] | [select all] lua
startStopWatch(ticktimer)
To get the remaining time:
Code: [show] | [select all] lua
function timeRemaining()
	local time = math.floor(getStopWatchTime(ticktimer))
	local minutes_remaining = math.floor((800-time)/60)
	local seconds_remaining = (800-time) % 60
	echo(minutes_remaining..":"..seconds_remaining.." remaining.\n")
end
On the final tick:
Code: [show] | [select all] lua
stopStopWatch(ticktimer)
resetStopWatch(ticktimer)

Post Reply