Add-ons / Playtime System

Records the player's total play time in hours, minutes, and seconds (though milliseconds are also tracked) and formats it for display via the <> macro.

Author ChapelR
Website https://twinelab.net/custom-macros-for-sugarcube-2/#/playtime-system
Story format SugarCube 2
Last checked Sun Jun 02 2019
License Unlicense
Download playtime.zip

Index

Overview

Records the player's total play time in hours, minutes, and seconds (though milliseconds are alos tracked) and formats it for display via the <<playtime>> macro. You can pause the timer with the pausetimer tag, and format your own output using the global playTime() function.

Macros

<<playtime>>

<<playtime>>

Syntax: <<playtime [format]>>

This macro shows the user their current playtime in hours, minutes and seconds. It will not update itself, but a <<repeat>> macro can be used to cause it to automatically update.

Arguments:

Usage:

<<playtime>>

<<playtime format>>

<<repeat 1s>>
    <<playtime>>
<</repeat>>

READ: Documentation

Passage tag pausetimer

Including the passage tag pausetimer will suspend the timer when the player is on said passage. May be useful for menus and such.

Usage notes

Variable warning

This system uses a story variable ($playtime by default) to store information in your game's state. You should avoid overwriting this variable, or change it using the configuration options.

Passage tag warning

This system uses a passage tag (pausetimer by default) to control parts of its operation. Avoid using this tag for other purposes, or change it using the configuration options.

Task object warning

This system creates a postdisplay tas object called start-playtime and a prehistory task object called pause-playtime. You should avoid using task objects with these names in your other code, though you can also re-name these task objects in the unminified script if you need to.

Configuration options

You can alter the story variable, passage tag, and whether the playTime() function is made global using the configuration options at the top of the script. See the unminified script for more info.

Live demo

Demo Twee code:

:: Start
Current play time: @@#time;<<playtime format>>@@
<<silently>>
    <<repeat 1s>>
        <<replace '#time'>><<playtime format>><</replace>>
    <</repeat>>
<</silently>>\