I'm trying to make a good data/hour system to my game, but numbers don't show leading zeros, so the hour shows like 2:5h, when I need 02:05h. How can I solve it? An insane block of ifs to check if is 0, them set to 00 (and if is 1, set 01, etc), can do the job, but it doesn't seems the right way.
The timestamp if formed by vars: $second, $minute, $hour, so using live, each second sets second var to +1. One way maybe is something like:
(if: $second is in (a:0,1,2,3,4,5,6,7,8,9))[ (set: $second to "0"+$second) ]
Of course it doesn't work (plus sign tries to sum string 0 with the var. But that's the idea...
Comments
One common method used when building an in-game time tracking system is to only track the smallest unit you are interested in and to derive the larger units as you need them. note: the above uses a the Javascript String slice function instead of the Harlowe (substring: ) macro because the macro needs an end position parameter which requires us to determine the length of the temporary $days/$hours strings.
Because you may want to display the DD:HHh output multiple times or in more than one place you should place the relevant code in a child passage and then (display:) that passage where you need it.
1. Place the following in a new passage named game-time 2. Examples of using the new game-time passage
The above could be modified to track game seconds instead.
So, I have the same clock (1 second to 1 second in-game), but I can control it anyway I need, for example taking the hour from the var $chour, or increasing time on each passage with (set: $cminute to it +X).
I'm not sure if this method has any major negative impact.