Game Development Community

dev|Pro Game Development Curriculum

Convert milliseconds to minutes+seconds format

by Bryce · 06/30/2012 (10:17 pm) · 5 comments

Without further ado, function:

function millisecondsToMinutesSeconds(%time)
{
   %te = %time / 1000;
   %te = %te / 60;
   %decimal = %te - mFloor(%te);
   %seconds = %decimal * 60;
   %minutes = %te - %decimal;
   %minutes = mCeil(%minutes);
   %seconds = mCeil(%seconds);
   return %minutes @ " minutes and " @ %seconds @ " seconds";
}


...One hundred words, eh? CAPS LOCK IS CRUISE CONTROL FOR COOL CAPS LOCK IS CRUISE CONTROL FOR COOL CAPS LOCK IS CRUISE CONTROL FOR COOL CAPS LOCK IS CRUISE CONTROL FOR COOL CAPS LOCK IS CRUISE CONTROL FOR COOL CAPS LOCK IS CRUISE CONTROL FOR COOL.

#1
07/01/2012 (8:03 am)
Um, how would you expect that to work when you have 4 semicolons and your using a pointer in torqueScript. I didn't know that this could be done. Don't all variables have to be defined with locally with % :P I think you wanted to append your string on the return statement.

return %minutes SPC %seconds;
#2
07/01/2012 (8:35 am)
Looks like he got bitten by the edit bug that replaces certain characters, especially quotes, with formatting garbage in the return line.
#3
07/01/2012 (9:04 am)
Quotes and Ampersands ... the bane of mankind since the dawn of time ... but only if he presses edit ...
#4
07/01/2012 (11:53 am)
562000 milliseconds is friendly to this human....

return %minutes @ " minutes and " @ %seconds @ " seconds";

Is what he meant - if you edit a post and use quotes, those quotes will be dropped and the " html version will be dropped in as placeholders (don't know why), so if you have to edit a post you should make it a habit to check for this before updating.
#5
07/02/2012 (10:31 am)
@Richard Ah ok, i didn't realize that the html did that when he posted haha. Thanks for clarifying that, because I was looking at his other resources and it seemed to me that he knew how to code :P.