generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: I'm terrible with math

Previous Thread :: Next Thread 
Jonibus is not online. Jonibus
Joined: 30 Jan 2010
Total Posts: 8985
20 Jun 2014 12:47 PM
What would be a nice way to convert minutes into hours and minutes?

Follow me on twitter: @Jonibus_RBX
Report Abuse
Locard is not online. Locard
Joined: 13 Apr 2014
Total Posts: 3516
20 Jun 2014 12:48 PM
local number = 182
local hours = math.floor(number/60)
local minutes = number-(60*hours)
Report Abuse
Phyclops is not online. Phyclops
Joined: 27 Sep 2012
Total Posts: 5895
20 Jun 2014 12:49 PM
use something like
if minutes.Value==>60 then


and make a value which is # hours # mins
and set the value to whatever it is above 60 as the mins and hours 1
etc
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 12:51 PM
local time = tick()
local hours = math.floor(time/3600)%24
local minutes = math.floor(time/60)%60
local seconds = math.floor(time)%60
print(hours .. ":" .. minutes)
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 12:54 PM
Actually, use this as the print line:

print(('%02i:%02i:%02i'):format(hours, minutes, seconds))
Report Abuse
jakej78b is not online. jakej78b
Joined: 09 Mar 2011
Total Posts: 813
20 Jun 2014 12:55 PM
Too lazy to pull out the ole' calculator?
Report Abuse
IAmTheRolo is not online. IAmTheRolo
Joined: 12 Nov 2013
Total Posts: 859
20 Jun 2014 12:55 PM
function ConvertMinutesToHoursAndMinutes(minutes)
local hours = 0
local new_minutes = 0
hours = math.floor(minutes/60)
new_minutes = minutes-(hours*60)
local new_time = hours.." hours and "..new_minutes.." minutes"
return new_time
end

local timeytime = ConvertMinutesToHoursAndMinutes(160)
print(timeytime)

>2 hours and 40 minutes
Report Abuse
Meowcatmaster is not online. Meowcatmaster
Joined: 20 Oct 2012
Total Posts: 769
20 Jun 2014 12:55 PM
Just use a calculator...
Report Abuse
Phyclops is not online. Phyclops
Joined: 27 Sep 2012
Total Posts: 5895
20 Jun 2014 12:57 PM
@jak
@meow

are you guys stupid?
he wants a script
i'm pretty sure he knows how to divide by 60
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 12:58 PM
Oh, MINUTES into HOURS and MINUTES.

Ok,

local time = 105 --Minutes

local hours = (time/60)%60
local minutes = (time)%60

print(('%02i:%02i or %i Hours %i Minutes'):format(hours, minutes, hours, minutes))
Report Abuse
Meowcatmaster is not online. Meowcatmaster
Joined: 20 Oct 2012
Total Posts: 769
20 Jun 2014 12:58 PM
Lol he said he's bad at math :P so I would guess not. (No offense)
Report Abuse
Jonibus is not online. Jonibus
Joined: 30 Jan 2010
Total Posts: 8985
20 Jun 2014 12:58 PM
They probably are, they assumed I'm doing math homework or something, rather than looking for an algorithm

Follow me on twitter: @Jonibus_RBX
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 01:00 PM
So, yeah. Use modulo, where you make a division and get the remainder. You can math.floor it, if you don't want a decimal, but if you are using it in a string you can just use string.format with %i (Integers) or %02i (Integers with a minimum of two "0"s, IE: 5 -> 05, 20 -> 20, 0 -> 00)
Report Abuse
Locard is not online. Locard
Joined: 13 Apr 2014
Total Posts: 3516
20 Jun 2014 01:01 PM
Notunknown,

I applaud your technique.
Report Abuse
jakej78b is not online. jakej78b
Joined: 09 Mar 2011
Total Posts: 813
20 Jun 2014 01:02 PM
He's capable of the script, he just needs the math part which about 5 people have provided him with so I'm sure he'll be fine. Sorry, I am pretty stupid btw @ FlamingTrollAbout
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 01:03 PM
Oh, and if the time in minutes can have decimals:

local time = 105.25

local hours = (time/60)%60
local minutes = (time)%60
local seconds = (time*60)%60 --Multiply by 60 to get the number of seconds

print(('%02i:%02i:%02i or %i Hours %i Minutes %i Seconds'):format(hours, minutes, seconds, hours, minutes, seconds))
Report Abuse
Jonibus is not online. Jonibus
Joined: 30 Jan 2010
Total Posts: 8985
20 Jun 2014 01:07 PM
Yeah, @jake I used Locard's method, because it made sense towards what I'm doing (a string containing hours and minutes in the sentence)

Notunknowns methods are great for clocks and timers, I'll take note of that for the future.

Follow me on twitter: @Jonibus_RBX
Report Abuse
jakej78b is not online. jakej78b
Joined: 09 Mar 2011
Total Posts: 813
20 Jun 2014 01:10 PM
Big fan of your zones too, I don't know why it hasn't replaced dart's yet. :v
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image