SecondsToTime (CMS)
From The Official Visionaire Studio: Adventure Game Engine Wiki
Name | Type | By |
---|---|---|
secondsToTime(v) | Definition | AFRLme |
This small function allows you to quickly convert seconds into the dd:hh:mm:ss 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, create an execute a script containing...
secondsToTime(86400) -- will return (01:00:00:00) 1 day, 0 hours, 0 minutes, 0 seconds.
2b. Here is an example of how you could use this function...
Values["play_time"].String = secondsToTime(Values["play_time"].ValueInt) -- 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
local d, h, m, s
function secondsToTime(v)
d = math.floor(v / 86400)
h = math.floor(v % 86400 / 3600)
m = math.floor(v % 3600 / 60)
s = math.floor(v % 3600 % 60)
-- + --
if d < 10 then d = tostring("0" .. d) end
if h < 10 then h = tostring("0" .. h) end
if m < 10 then m = tostring("0" .. m) end
if s < 10 then s = tostring("0" .. s) end
-- + --
return tostring( d .. ":" .. h .. ":" .. m .. ":" .. s )
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 dd:hh:mm:ss time format. |