Pico-8 API Documentation
Pico-8
Pico-8
execution flow
_init() -- called once on program startup_update() -- called once per update at 30fps_update60() -- called once per update at 60fps_draw() -- called once per visible frameCLI
assert(condition) -- verify that condition is truecd .. -- change to parent directorycd [dirname] -- change directorydir() -- list itemsexit() -- close pico-8 appexport(filename.html, [cart1.p8, cart2.p8 ... cart15]) -- export game in html; up to 15 extra carts (.p8 format)export(filename.png) -- export spritesheetexport(filename.wav) -- export the current sfx / musicexport(filename%d.wav) -- export all sfx as numbered filesextcmd(cmd) -- control screenshots; "label" = cart label; "screen" = screenshot; "rec" = start gif; "video" = save giffolder() -- open carts folder in operating systemhelp() -- show summary of system commandsimport(filename.png) -- import spritesheet. expects 128x128 png and colour-fits to the pico-8 paletteinfo() -- print cart infoinstall_demos() -- install demo p8 carts alongside pico-8 appinstall_games() -- install selection of bbs cartskeyconfig() -- keyboard configuration for player buttonsload("@clip") -- paste cart from clipboard, bbs supportload(filename) -- load cart; works with multi-cart exportls() -- list itemsmenuitem(index, [label, callback]) -- add an extra item to the pause menu; index in [1..5]; no label or callback removes the itemmkdir(dirname) -- create directoryprinth(str, [filename, overwrite]) -- print str to terminal; append or overwrite to filenamereboot() -- reboot pico8resume() -- resume cart executionrun() -- boot cartsave("@clip") -- copy cart to clipboard, bbs supportsave(filename) -- save cartshutdown() -- close pico-8 appsplore() -- explore cartridgesstat(x) -- read some execution values, read belowtime() -- returns seconds since last reboottype(v) -- returns type of v: number, string or tablestats
stat(0) -- memory usage in [0..1024]stat(1) -- cpu usage; 1.0 == 100% cpu at 30fpsstat(4) -- clipboard; after user pressed ctrl-vstat([16..19]) -- index of playing sfx on channels [0..3]stat([20..23]) -- note number (0..31) on channels [0..3]stat(30) -- keyboard key hit; see "peek / poke" tabstat(31) -- keyboard character; see "peek / poke" tabstat(32) -- mouse x coord; see "peek / poke" tabstat(33) -- mouse y coord; see "peek / poke" tabstat(34) -- mouse button bitmask; see "peek / poke" tabjavascript
pico8_gpio[] // read and write gpio pinspico8_buttons[] // bitfields for player inputdebugging
-- After running the game with ctrl + r, press escape to pause execution. -- Entering a '.' into the console will advance the game to the next frameenter -- Continue entering the '.' character or simply press enterprint(player.x) -- Show the current, live x value of the player. Game does not cease execution, & updates each frame!?player.x -- '?' functions just like 'print' and can be used in place as shorthandresume() -- The 'resume' function will return the game to a normal running state.private functions
_get_frames_skipped() -- used automatically by _mainloop()_get_menu_item_selected(n) -- returns true or false if the n-th menu item is selected; n in [1..5]; used automatically by _mainloop()_mainloop() -- main pico-8's "while true"_pausemenu[n].callback() -- execute the n-th menu item's callback; n in [1..5]; used automatically by _mainloop()_set_mainloop_exists(n) -- ?_update_buttons() -- used automatically by _mainloop()holdframe() -- used automatically by _mainloop()