- Returns the amount of time since PICO-8 was last started, as a (fractional) number of seconds.
time() function returns the (fractional) number of seconds since PICO-8 was started.
time() multiple times in the same frame will always return the same result.
PICO-8's number type has an upper limit of 32767.9999 before it wraps back to -32768. This means the values from
time() may become problematic after roughly 9 hours and 6 minutes. An app that needs to track elapsed times of significant duration would be wise to track time as a series of delta-times, accumulating them into a representation capable of tracking longer periods.
Time may also be measured in several different ways, and at high resolution, through the system stats. See the
stat() function for details.
As of v0.2.4b, carts with a Game Loop will only see
time() update when their Game Loop loops - it won't update if they call
There is a semi-documented alias to the
time() function in the form of
t(). This may be useful for carts that are tight on source code space, most notably Tweetcarts.
function _init() last = time() end function _update() -- (empty update to use game loop) end function _draw() cls() if (time() - last) > 10 then print("time's up!", 44, 60, 7) end end