stat( n )

Returns information about the current runtime environment.

The ID of the information to return. (See below.)

The stat() function returns information about the current runtime environment. Each kind of information has an ID (a number), described below.

You can display this metric on the game screen with print(), write it to the console with printh(), or perhaps use it some other way to adjust the behavior of your program.

Memory and CPU usage Edit

stat(0) returns the amount of memory currently used by the Lua program. The value is a number of megabytes, between 0 and 1024.

stat(1) returns the CPU usage since the last frame was drawn. A value of 1.0 indicates that the program was executing code 100% of the time between frames at 30 frames per second. A value higher than 1.0 indicates that the program is taking too long between frames to draw at 30 frames per second reliably.

Clipboard contents Edit

A running Pico-8 cartridge can access the contents of the system clipboard. It can do so if and only if the user presses the "paste" key sequence, either Control-v (Windows, Linux) or Command-v (Mac OS X). (This is to prevent a program from accessing the clipboard without the user's permission.)

stat(4) returns the clipboard contents, as a string.

Sound status Edit

stat(16) through stat(19) return the index of the sound effect currently playing on the four channels, respectively. If no sound is playing on the channel, stat() returns -1.

stat(20) through stat(23) return the note number (0 through 31) of the sound effect currently playing on the four channels, respectively. If no sound is playing on the channel, stat() returns -1.

From zep: "Note that the row number may not be very precise depending on what is going on with the host operating system's audio mixer. Also in the case of the web player which needs to have a large mixing buffer, the result is often slightly earlier that what is audible."

Devkit mouse mode Edit

Undocumented feature
This article describes a feature that is not mentioned in the official Pico-8 documentation. The feature was known to work at the time the article was written, but it may be removed or changed in a future version.

You can enable the mouse pointer (for platforms with a mouse) inside a cart:

poke(0x5F2D, 1)

Once enabled, you can use stat(...) to read mouse values:

  • stat(32) -> X coord
  • stat(33) -> Y coord
  • stat(34) -> button bitmask (1=primary, 2=secondary, 4=middle)

From zep: "For what it's worth, I don't think of the mouse as a console feature (hence leaving it undocumented & off-spec), but rather a development kit thing. For anyone using the mouse, keep in mind that not every PICO-8 will have mouse support, so it's better suited to things like tools filed under collab, or at least as an additional, alternative way of controlling a cursor."

Also: "Although mouse reading will be supported going forward, just a heads up that in the future reading the mouse will likely trigger a small "devkit mouse enabled" message to show at the bottom of the screen briefly when playing carts via the bbs. This will hopefully avoid confusion from gamepad-only splore users, and also nudge mouse-controlled carts more into the "dev tools" domain (along with carts that read from multiple other cartridges)."

Examples Edit

function _update()
  -- game update code...

function _draw()

  -- game draw code...

  print('mem:'..stat(0), 0, 0, 7)
  print('cpu:'..stat(1), 0, 8, 7)

See also Edit

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.