PICO-8 Wiki
(→‎Debugging: update args to assert)
(prefer code tag over nowiki tag)
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
  +
This is a list of functions provided by PICO-8's Lua-based [https://en.wikipedia.org/wiki/Application_programming_interface API] .
An [https://en.wikipedia.org/wiki/Application_programming_interface API] function is a function provided by Pico-8's API that you can call from a cartridge's source code. You can also call API functions from the Pico-8 [[CommandPrompt|command prompt]].
 
  +
  +
Typically you run these functions by writing them in the code editor and using the [[Run]] command to run your program. You can also call API functions from the PICO-8 [[CommandPrompt|command prompt]].
   
 
== Calling functions ==
 
== Calling functions ==
Line 25: Line 27:
 
== The game loop ==
 
== The game loop ==
   
If you define these functions in your code, Pico-8 will call them at specific times. See [[GameLoop|Game loop]].
+
If you define these functions in your code, PICO-8 will call them at specific times. See [[GameLoop|Game loop]].
   
* [[Init|<nowiki>_init()</nowiki>]]
+
* [[Init|<code>_init()</code>]]
* [[Update|<nowiki>_update()</nowiki>]]
+
* [[Update|<code>_update()</code>]]
* [[Draw|<nowiki>_draw()</nowiki>]]
+
* [[Draw|<code>_draw()</code>]]
   
 
If your code doesn't use the game loop, you can call this function to copy the graphics buffer to the screen:
 
If your code doesn't use the game loop, you can call this function to copy the graphics buffer to the screen:
   
* [[Flip|<nowiki>flip()</nowiki>]]
+
* [[Flip|<code>flip()</code>]]
   
 
== Graphics ==
 
== Graphics ==
   
* [[Camera|<nowiki>camera([x,] [y])</nowiki>]]
+
* [[Camera|<code>camera([x,] [y])</code>]]
* [[Circ|<nowiki>circ(x, y, r, [col])</nowiki>]]
+
* [[Circ|<code>circ(x, y, r, [col])</code>]]
* [[Circfill|<nowiki>circfill(x, y, r, [col])</nowiki>]]
+
* [[Circfill|<code>circfill(x, y, r, [col])</code>]]
* [[Clip|<nowiki>clip([x,] [y,] [w,] [h])</nowiki>]]
+
* [[Clip|<code>clip([x,] [y,] [w,] [h])</code>]]
* [[Cls|<nowiki>cls()</nowiki>]]
+
* [[Cls|<code>cls()</code>]]
* [[Color|<nowiki>color(col)</nowiki>]]
+
* [[Color|<code>color(col)</code>]]
* [[Cursor|<nowiki>cursor(x, y)</nowiki>]]
+
* [[Cursor|<code>cursor([x,] [y,] [col])</code>]]
* [[Fget|<nowiki>fget(n, [f])</nowiki>]]
+
* [[Fget|<code>fget(n, [f])</code>]]
* [[Fillp|<nowiki>fillp([pat])</nowiki>]]
+
* [[Fillp|<code>fillp([pat])</code>]]
* [[Fset|<nowiki>fset(n, [f,] [v])</nowiki>]]
+
* [[Fset|<code>fset(n, [f,] [v])</code>]]
* [[Line|<nowiki>line(x0, y0, x1, y1, [col])</nowiki>]]
+
* [[Line|<code>line(x0, y0, x1, y1, [col])</code>]]
* [[Pal|<nowiki>pal([c0,] [c1,] [p])</nowiki>]]
+
* [[Pal|<code>pal([c0,] [c1,] [p])</code>]]
* [[Palt|<nowiki>palt([c,] [t])</nowiki>]]
+
* [[Palt|<code>palt([c,] [t])</code>]]
* [[Pget|<nowiki>pget(x, y)</nowiki>]]
+
* [[Pget|<code>pget(x, y)</code>]]
* [[Print|<nowiki>print(str, [x,] [y,] [col])</nowiki>]]
+
* [[Print|<code>print(str, [x,] [y,] [col])</code>]]
* [[Pset|<nowiki>pset(x, y, [c])</nowiki>]]
+
* [[Pset|<code>pset(x, y, [c])</code>]]
* [[Rect|<nowiki>rect(x0, y0, x1, y1, [col])</nowiki>]]
+
* [[Rect|<code>rect(x0, y0, x1, y1, [col])</code>]]
* [[Rectfill|<nowiki>rectfill(x0, y0, x1, y1, [col])</nowiki>]]
+
* [[Rectfill|<code>rectfill(x0, y0, x1, y1, [col])</code>]]
* [[Sget|<nowiki>sget(x, y)</nowiki>]]
+
* [[Sget|<code>sget(x, y)</code>]]
* [[Spr|<nowiki>spr(n, x, y, [w,] [h,] [flip_x,] [flip_y])</nowiki>]]
+
* [[Spr|<code>spr(n, x, y, [w,] [h,] [flip_x,] [flip_y])</code>]]
* [[Sset|<nowiki>sset(x, y, [c])</nowiki>]]
+
* [[Sset|<code>sset(x, y, [c])</code>]]
* [[Sspr|<nowiki>sspr(sx, sy, sw, sh, dx, dy, [dw,] [dh,] [flip_x,] [flip_y])</nowiki>]]
+
* [[Sspr|<code>sspr(sx, sy, sw, sh, dx, dy, [dw,] [dh,] [flip_x,] [flip_y])</code>]]
 
See also [[Graphics]].
 
See also [[Graphics]].
   
 
== Tables ==
 
== Tables ==
   
* [[Add|<nowiki>add(t, v)</nowiki>]]
+
* [[Add|<code>add(t, v)</code>]]
* [[All|<nowiki>all(t)</nowiki>]]
+
* [[All|<code>all(t)</code>]]
* [[Del|<nowiki>del(t, v)</nowiki>]]
+
* [[Del|<code>del(t, v)</code>]]
* [[Foreach|<nowiki>foreach(t, f)</nowiki>]]
+
* [[Foreach|<code>foreach(t, f)</code>]]
* [[Pairs|<nowiki>pairs(t)</nowiki>]]
+
* [[Pairs|<code>pairs(t)</code>]]
   
 
See also [[Lua]], [[Tables]].
 
See also [[Lua]], [[Tables]].
Line 73: Line 75:
 
== Input ==
 
== Input ==
   
* [[Btn|<nowiki>btn([i,] [p])</nowiki>]]
+
* [[Btn|<code>btn([i,] [p])</code>]]
* [[Btnp|<nowiki>btnp([i,] [p])</nowiki>]]
+
* [[Btnp|<code>btnp([i,] [p])</code>]]
   
 
== Sound ==
 
== Sound ==
   
* [[Music|<nowiki>music([n,] [fade_len,] [channel_mask])</nowiki>]]
+
* [[Music|<code>music([n,] [fade_len,] [channel_mask])</code>]]
* [[Sfx|<nowiki>sfx(n, [channel,] [offset])</nowiki>]]
+
* [[Sfx|<code>sfx(n, [channel,] [offset])</code>]]
   
 
== Map ==
 
== Map ==
   
* [[Map|<nowiki>map(cel_x, cel_y, sx, sy, cel_w, cel_h, [layer])</nowiki>]]
+
* [[Map|<code>map(cel_x, cel_y, sx, sy, cel_w, cel_h, [layer])</code>]]
* [[Mget|<nowiki>mget(x, y)</nowiki>]]
+
* [[Mget|<code>mget(x, y)</code>]]
* [[Mset|<nowiki>mset(x, y, v)</nowiki>]]
+
* [[Mset|<code>mset(x, y, v)</code>]]
   
 
== Memory ==
 
== Memory ==
   
* [[Cstore|<nowiki>cstore(dest_addr, source_addr, len, [filename])</nowiki>]]
+
* [[Cstore|<code>cstore(dest_addr, source_addr, len, [filename])</code>]]
* [[Memcpy|<nowiki>memcpy(dest_addr, source_addr, len)</nowiki>]]
+
* [[Memcpy|<code>memcpy(dest_addr, source_addr, len)</code>]]
* [[Memset|<nowiki>memset(dest_addr, val, len)</nowiki>]]
+
* [[Memset|<code>memset(dest_addr, val, len)</code>]]
* [[Peek|<nowiki>peek(addr)</nowiki>]]
+
* [[Peek|<code>peek(addr)</code>]]
* [[Poke|<nowiki>poke(addr, val)</nowiki>]]
+
* [[Poke|<code>poke(addr, val)</code>]]
* [[Reload|<nowiki>reload(dest_addr, source_addr, len, [filename])</nowiki>]]
+
* [[Reload|<code>reload(dest_addr, source_addr, len, [filename])</code>]]
   
 
== Math ==
 
== Math ==
   
* [[Abs|<nowiki>abs(x)</nowiki>]]
+
* [[Abs|<code>abs(x)</code>]]
* [[Atan2|<nowiki>atan2(dx, dy)</nowiki>]]
+
* [[Atan2|<code>atan2(dx, dy)</code>]]
* [[Band|<nowiki>band(x, y)</nowiki>]]
+
* [[Band|<code>band(x, y)</code>]]
* [[Bnot|<nowiki>bnot(x)</nowiki>]]
+
* [[Bnot|<code>bnot(x)</code>]]
* [[Bor|<nowiki>bor(x, y)</nowiki>]]
+
* [[Bor|<code>bor(x, y)</code>]]
* [[Bxor|<nowiki>bxor(x, y, )</nowiki>]]
+
* [[Bxor|<code>bxor(x, y)</code>]]
* [[Cos|<nowiki>cos(x)</nowiki>]]
+
* [[Cos|<code>cos(x)</code>]]
* [[Flr|<nowiki>flr(x)</nowiki>]]
+
* [[Flr|<code>flr(x)</code>]]
* [[Max|<nowiki>max(x, y)</nowiki>]]
+
* [[Max|<code>max(x, y)</code>]]
* [[Mid|<nowiki>mid(x, y, z)</nowiki>]]
+
* [[Mid|<code>mid(x, y, z)</code>]]
* [[Min|<nowiki>min(x, y)</nowiki>]]
+
* [[Min|<code>min(x, y)</code>]]
* [[Rnd|<nowiki>rnd(x)</nowiki>]]
+
* [[Rnd|<code>rnd(x)</code>]]
* [[Shl|<nowiki>shl(x, y)</nowiki>]]
+
* [[Shl|<code>shl(x, y)</code>]]
* [[Shr|<nowiki>shr(x, y)</nowiki>]]
+
* [[Shr|<code>shr(x, y)</code>]]
* [[Sin|<nowiki>sin(x)</nowiki>]]
+
* [[Sin|<code>sin(x)</code>]]
* [[Sqrt|<nowiki>sqrt(x)</nowiki>]]
+
* [[Sqrt|<code>sqrt(x)</code>]]
* [[Srand|<nowiki>srand(x)</nowiki>]]
+
* [[Srand|<code>srand(x)</code>]]
   
 
See also [[Math]].
 
See also [[Math]].
Line 120: Line 122:
 
== Cartridge data ==
 
== Cartridge data ==
   
* [[Cartdata|<nowiki>cartdata(id)</nowiki>]]
+
* [[Cartdata|<code>cartdata(id)</code>]]
* [[Dget|<nowiki>dget(index)</nowiki>]]
+
* [[Dget|<code>dget(index)</code>]]
* [[Dset|<nowiki>dset(index, value)</nowiki>]]
+
* [[Dset|<code>dset(index, value)</code>]]
   
 
== Coroutines ==
 
== Coroutines ==
   
* [[Cocreate|<nowiki>cocreate(func)</nowiki>]]
+
* [[Cocreate|<code>cocreate(func)</code>]]
* [[Coresume|<nowiki>coresume(cor)</nowiki>]]
+
* [[Coresume|<code>coresume(cor)</code>]]
* [[Costatus|<nowiki>costatus(cor)</nowiki>]]
+
* [[Costatus|<code>costatus(cor)</code>]]
* [[Yield|<nowiki>yield()</nowiki>]]
+
* [[Yield|<code>yield()</code>]]
   
 
== Values and objects ==
 
== Values and objects ==
   
* [[Setmetatable|<nowiki>setmetatable(tbl, metatbl)</nowiki>]]
+
* [[Setmetatable|<code>setmetatable(tbl, metatbl)</code>]]
* [[Getmetatable|getmetatable(tbl)]]
+
* [[Getmetatable|<code>getmetatable(tbl)</code>]]
* [[Type|<nowiki>type(v)</nowiki>]]
+
* [[Type|<code>type(v)</code>]]
* [[Sub|<nowiki>sub(str, from, [to])</nowiki>]]
+
* [[Sub|<code>sub(str, from, [to])</code>]]
* [[Tonum|tonum(str)]]
+
* [[Tonum|<code>tonum(str)</code>]]
* [[Tostr|tostr(val, [usehex])]]
+
* [[Tostr|<code>tostr(val, [usehex])</code>]]
   
 
See also [[Lua]], [[Strings]], [[Tables]], [[Metatables]].
 
See also [[Lua]], [[Strings]], [[Tables]], [[Metatables]].
Line 144: Line 146:
 
== Time ==
 
== Time ==
   
* [[Time|<nowiki>time()</nowiki>]]
+
* [[Time|<code>time()</code>]]
   
 
== System ==
 
== System ==
   
* [[Menuitem|<nowiki>menuitem(index, [label, callback])</nowiki>]]
+
* [[Menuitem|<code>menuitem(index, [label, callback])</code>]]
* [[Extcmd|extcmd(cmd)]]
+
* [[Extcmd|<code>extcmd(cmd)</code>]]
   
 
== Debugging ==
 
== Debugging ==
   
* [[Assert|<nowiki>assert(cond, [message])</nowiki>]]
+
* [[Assert|<code>assert(cond, [message])</code>]]
* [[Printh|<nowiki>printh(str, [filename], [overwrite])</nowiki>]]
+
* [[Printh|<code>printh(str, [filename], [overwrite])</code>]]
* [[Stat|<nowiki>stat(n)</nowiki>]]
+
* [[Stat|<code>stat(n)</code>]]
* [[Stop|stop()]] (undocumented)
+
* [[Stop|<code>stop()</code>]] (undocumented)
* [[Trace|trace()]] (undocumented)
+
* [[Trace|<code>trace()</code>]] (undocumented)
   
 
== See also ==
 
== See also ==

Revision as of 00:22, 10 November 2019

This is a list of functions provided by PICO-8's Lua-based API .

Typically you run these functions by writing them in the code editor and using the Run command to run your program. You can also call API functions from the PICO-8 command prompt.

Calling functions

Some functions have optional arguments, indicated in this guide by square brackets around the argument name. To specify a value for an optional argument, you must specify values for all other arguments to the left in the argument list.

For example, the spr() function has three required arguments and four optional arguments:

spr( n, x, y, [w,] [h,] [flip_x,] [flip_y] )

This function can be called with three arguments, accepting the defaults for the others:

spr(1, 60, 60)

To specify a value for the flip_x argument, you must also specify w and h, even if you're using their default values:

spr(1, 60, 60, 1, 1, true)

The game loop

If you define these functions in your code, PICO-8 will call them at specific times. See Game loop.

If your code doesn't use the game loop, you can call this function to copy the graphics buffer to the screen:

Graphics

See also Graphics.

Tables

See also Lua, Tables.

Input

Sound

Map

Memory

Math

See also Math.

Cartridge data

Coroutines

Values and objects

See also Lua, Strings, Tables, Metatables.

Time

System

Debugging

See also