PICO-8 Wiki
Advertisement
time( )
Returns the amount of time since PICO-8 was last started, as a (fractional) number of seconds.

The time() function returns the (fractional) number of seconds since PICO-8 was started.

Calling time() multiple times in the same frame will always return the same result.

Technical notes[]

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 flip() manually.

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.

Examples[]

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

See Also[]

Advertisement