SecondsToHours (CMS)

From The Official Visionaire Studio: Adventure Game Engine Wiki
Name Type By
secondsToHours(v, b) Definition AFRLme

This small function allows you to quickly convert seconds into the hh time format.

d = day, h = hour, m = minute, s = seconds.
There are 86400 seconds in a day, 3600 seconds in an hour & 60 seconds in a minute.


Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2a. To use this function (with day calculation enabled), create an execute a script containing...

secondsToHours(86400, true) -- will return (00) 0 hours, because we have declared that it should take days into consideration too.

2b. To use this function (with day calculation disabled), create an execute a script containing...

secondsToHours(86400, false) -- will return (24) 24 hours, because we have declared that it should not take days into consideration.

2c. Here is an example of how you could use this function...

Values["hours"].String = secondsToHours(Values["play_time"].ValueInt, false) -- here we are converting the integer value stored in the integer field of the value into a string time format which can be returned in a displayed text action part using the <vs=value_name> field.

Main Script

function secondsToHours(v, b)
 if b then v = math.floor(v % 86400 / 3600) else v = math.floor(v / 3600) end
 -- + --
 if v < 10 then v = tostring("0" .. v) end
 -- + --
 return tostring( v )
end

Syntax Breakdown

Name Type Description
v integer This should be an integer (number) value of the amount of seconds you want to split into the hh time format.
b boolean This should be a boolean value of true or false.