Difference between revisions of "SecondsToDays (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Created page with "{| class="ts" style="width:100%" |- ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By |- | secondsToDays(v) || Definition || A...")
 
m
Line 30: Line 30:
 
local d
 
local d
  
function secondsToTime(v)
+
function secondsToDays(v)
 
  d = math.floor(v / 86400)
 
  d = math.floor(v / 86400)
 
  -- + --
 
  -- + --

Revision as of 15:13, 22 February 2015

Name Type By
secondsToDays(v) Definition AFRLme

This small function allows you to quickly convert seconds into the dd 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) 1 day.

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

function secondsToDays(v)
 d = math.floor(v / 86400)
 -- + --
 if d < 10 then d = tostring("0" .. d) end
 -- + --
 return tostring( d )
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 time format.