Playtime Counter (h2)

From The Official Visionaire Studio: Adventure Game Engine Wiki
Revision as of 22:55, 22 February 2015 by AFRLme (talk)
Name By

Playtime Counter (action part, value & lua) AFRLme


This tutorial shows you how to create a playtime counter using a single value, some action parts & a few lines of Lua script.


Tutorial

1. Create a new script inside of the script section of the editor & add the script inside of the code block below into it.

local d, h, m, s -- empty variables which will be used to store converted time values
 
--* function which converts seconds to days, hours, minutes & seconds * --
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

2. Next you are going to want to create a value somewhere. Name it playtime & set the default value to 0.

Playtime counter2 001.png

3. Now go to the actions tab of the scene that you are wanting to display the timer on. Create an at begin of scene action, an at end of scene action & 2 called by other actions. Name the called by other actions: update_playtime & update_playtime_text.

Playtime counter2 002.png

4. Inside of the at begin of scene action: add these action parts...

execute a script > (see code block below)
call action 'update_playtime_text'
call action 'update_playtime' 
Values["playtime"].String = secondsToTime( Values["playtime"].ValueInt )

Playtime counter2 003.png


Resources

Name Description
playtime_counter-2.zip A working .ved file, complete with resources. Check out the readme.txt file for instructions.