Warcraft III resources & community, 2003–2006 · archived

Real to Minutes and Seconds

not rated
Submitted by a_thingConversion0 downloads
This function takes a real, then returns a string that is that real in minutes and seconds. ex: If it takes 70, it will return "1 minute and 10 seconds".

Source

function R2MS takes real seconds returns string
    local string minutes
    local string Seconds
    local string returnstring = I2S(R2I(seconds)) + " seconds"
    if seconds == 1 then
        return "1 second"
    endif
    //check if seconds is a multiple of 60
    if ModuloReal(seconds, 60) == 0 then
        if seconds/60 == 1 then
            return "1 minute"
        else
            if SubStringBJ(R2S(seconds/60), 2, 2) == "." then
                return SubStringBJ(R2S(seconds/60), 1, 1) + " minutes"
            else
                return SubStringBJ(R2S(seconds/60), 1, 2) + " minutes"
            endif
        endif
    endif
    if seconds < 60 then
        return returnstring
    else
        //set minutes
        if seconds/60 < 10 then
            set minutes = SubStringBJ(R2S(seconds/60), 1, 1)
        else
            set minutes = SubStringBJ(R2S(seconds/60), 1, 2)
        endif
        //set Seconds
        if SubStringBJ(R2S(ModuloReal(seconds, 60)), 2, 2) == "." then
            set Seconds = SubStringBJ(R2S(ModuloReal(seconds, 60)), 1, 1)
        else
            set Seconds = SubStringBJ(R2S(ModuloReal(seconds, 60)), 1, 2)
        endif
        //set returnstring
        if minutes == "1" then
            if Seconds == "1" then
                set returnstring = minutes + " minute and " + Seconds +" second"
            else
                set returnstring = minutes + " minute and " + Seconds +" seconds"
            endif
        else
            if Seconds == "1" then
                set returnstring = minutes + " minutes and " + Seconds +" second"
            else
                set returnstring = minutes + " minutes and " + Seconds +" seconds"
            endif
        endif
    endif
    return returnstring
endfunction

Comments

8
1. If your map lasts 100 minutes, I think you really need to do a lot of work on it.

2. If you passed the function a real that would be over 99 minutes 59 seconds it would return the first two didgets of the minutes as the minutes.
What happens if u put in to much and it cant convert to hours?
Um.... I knew that. :oops:
but why not just use R2I, remember R2I always rounds down.
I have all that substring stuff in there because without that stuff minutes and seconds would be reals and not integers.

function R2Ms takes real x returns string
local integer min = R2I(x/60)
local integer sec = I2S(ModuloReal(x/60)+0.5)
local string txt = ""
if min != 0 then
    set txt = I2S(min)+ " minute"
  if min > 1 then
    set txt = I2S(min)+ " minutes"
  endif
  if sec != 0 then
    set txt = txt + " and "
  endif
endif
if sec != 0 then
 set txt = txt + I2S(sec)
 if sec>1 then
   set txt = txt+" seconds"
 else
   set txt = txt+" second"
 endif
endif
return txt
endfunction



here, not to offend you but wouldn't this be a better solution? its not tested but it should work.
Thanks for pointing that out. I updated the function.
What about if i pass it 60 seconds?

Or just 1 second?

It will return 1 minute and 0 seconds...
And 1 seconds.

Doesnt really matter but i'd add if seconds == 60, return seconds / 60 minute. or just 1.
and if seconds = 1 return second


Nice script though ;)