HMSfromFloat24h

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

A User Function for use with Oblivion Script Extender


Syntax:

(hh:mm:ssstring) HMSfromFloat24h  Valuefloat

Converts a value into a "hh:mm:ss" formatted string

Value is supposed to contain the hour + decimals, like the value returned by GameHour


Notes[edit | edit source]

  • Value is normalized to 0-24 (e.g.: value 30,5 returns "06:30:00", value -1 returns "23:00:00")


Examples:[edit | edit source]

Call HMSfromFloat24h 10,5         ; returns "10:30:00"
Call HMSfromFloat24h 17.25        ; returns "17:15:00"
Call HMSfromFloat24h GameHour     ; returns the formatted game time


Code[edit | edit source]

scn HMSfromFloat24h  
;---------------------------------------------------------------------
;   Converts an hour value into a formated string
;===================================
;  Input: a float containing the hour and decimals like the one returned by GameHour
;  Returns: a string formatted as "hh:mm:ss"
;
;  Usage: Call HMSfromFloat24h GameHour
;---------------------------------------------------------------------
string_var sTime
float value
float vtime
short ihour
short imin 
short isec
short i

begin Function {value} 

  ;=== Normalize to 0-24 ===
  let i := value / 24
  let vtime := value - i * 24
  if vtime < 0
    let vtime := vtime + 24
  endif

 ;=== Format the Hour ===
  set ihour to vtime
  if ihour < 10
    let sTime := "0" + $ihour + ":"
  else
    let sTime := $ihour + ":"
  endif

  ;=== Format Minutes ===
  set vtime to vtime - ihour
  set vtime to vtime * .6 * 100
  set imin to vtime 
  if imin < 10
    let sTime := sTime + "0" + $imin + ":" 
  else
    let sTime := sTime + $imin + ":" 
  endif

  ;=== Format Seconds ===
  set vtime to vtime - imin 
  set vtime to vtime * .6 * 100
  set isec to vtime 
  if vtime < 10
    let sTime := sTime + "0" + $isec 
  else
    let sTime := sTime + $isec 
  endif

  SetFunctionValue  sTime 

end


See Also[edit | edit source]