|
| 15 Jul 2013 01:15 PM |
This is more of a math question than a scripting question, but I was wondering if there is a math equation that would turn seconds into hours and minutes. This way I could display a player's time-played in a tidy fashion. Of course, I could always add 1 to minutes every time seconds reached 60 and reset seconds, but I thought I might as well check if there was a math equation for it instead.
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
Zomebody
|
  |
| Joined: 01 Jun 2010 |
| Total Posts: 789 |
|
|
| 15 Jul 2013 01:31 PM |
I think these two methods can help you:
math.fmod() math.modf()
I found them on this page: http://wiki.roblox.com/index.php/Math.modf#math.fmod
I used these two methods already to make timer in minutes and seconds, so I think it would also be possible for you to use this to make a timer with hours, minutes and seconds. |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2013 01:35 PM |
The wiki article on that is confusing, and I haven't reached a point in math that I'd learn what those do (I just finished grade 9). Would you not mind providing me an example or two on how I'd use them?
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 15 Jul 2013 01:37 PM |
Think of a second as the base unit. A minute is made from 60 seconds. An hour is made from 60 minutes. A day is made from 24 hours.
If you have the number of seconds, you can easily get the number of minutes, and I want you to think about how that would be done. |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2013 01:45 PM |
I tried adding a bit of subtraction to the script I came up with yesterday, and I think it might be working... but I'm not sure. Is this correct?
local seconds = math.random(100000) local days = math.floor(seconds / 86400) seconds = seconds - (days * 86400) local hours = math.floor(seconds / 3600) seconds = seconds - (hours * 3600) local minutes = math.floor(seconds / 60) seconds = seconds - (minutes * 60) print(days.."d,", hours.."h,", minutes.."m,", seconds.."s")
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 15 Jul 2013 01:55 PM |
| Yes, that correctly divides a bunch of seconds into days, hours, minutes and seconds. |
|
|
| Report Abuse |
|
|