PICO-8 Wiki
Register
(ovals)
Tag: Source edit
(Update with new APIs, split strings to own section, better mention stat)
Tag: Visual edit
(6 intermediate revisions by 2 users not shown)
Line 45: Line 45:
 
* [[Ovalfill|<code>ovalfill(x0, y0, x1, y1, [col])</code>]]
 
* [[Ovalfill|<code>ovalfill(x0, y0, x1, y1, [col])</code>]]
 
* [[Clip|<code>clip([x,] [y,] [w,] [h])</code>]]
 
* [[Clip|<code>clip([x,] [y,] [w,] [h])</code>]]
* [[Cls|<code>cls()</code>]]
+
* [[Cls|<code>cls([col])</code>]]
 
* [[Color|<code>color(col)</code>]]
 
* [[Color|<code>color(col)</code>]]
 
* [[Cursor|<code>cursor([x,] [y,] [col])</code>]]
 
* [[Cursor|<code>cursor([x,] [y,] [col])</code>]]
Line 68: Line 68:
 
== Tables ==
 
== Tables ==
   
* [[Add|<code>add(t, v)</code>]]
+
* [[Add|<code>add(t, v, [i])</code>]]
 
* [[All|<code>all(t)</code>]]
 
* [[All|<code>all(t)</code>]]
 
*<code>[[Count|count(t, [v])]]</code>
 
*<code>[[Count|count(t, [v])]]</code>
Line 75: Line 75:
 
* [[Foreach|<code>foreach(t, f)</code>]]
 
* [[Foreach|<code>foreach(t, f)</code>]]
 
*<code>[[IPairs|ipairs(t)]]</code>
 
*<code>[[IPairs|ipairs(t)]]</code>
 
*[[Pack|<code>pack(...)</code>]]
 
* [[Pairs|<code>pairs(t)</code>]]
 
* [[Pairs|<code>pairs(t)</code>]]
 
* <code>[[Unpack|unpack(t, [i], [j])]]</code>
 
*<code>[[Next|next(t, [key])]]</code>
 
*<code>[[Next|next(t, [key])]]</code>
   
Line 84: Line 86:
 
* [[Btn|<code>btn([i,] [p])</code>]]
 
* [[Btn|<code>btn([i,] [p])</code>]]
 
* [[Btnp|<code>btnp([i,] [p])</code>]]
 
* [[Btnp|<code>btnp([i,] [p])</code>]]
  +
See also [[Stat#.7B30.E2.80.A639.7D Mouse and Keyboard|Stat: Mouse and Keyboard]]
   
 
== Sound ==
 
== Sound ==
Line 89: Line 92:
 
* [[Music|<code>music([n,] [fade_len,] [channel_mask])</code>]]
 
* [[Music|<code>music([n,] [fade_len,] [channel_mask])</code>]]
 
* [[Sfx|<code>sfx(n, [channel,] [offset])</code>]]
 
* [[Sfx|<code>sfx(n, [channel,] [offset])</code>]]
  +
See also [[Stat#.7B108.E2.80.A6109.7D 5kHz PCM Audio|Stat: PCM (undocumented)]]
   
 
== Map ==
 
== Map ==
Line 98: Line 102:
 
== Memory ==
 
== Memory ==
   
* [[Cstore|<code>cstore(dest_addr, source_addr, len, [filename])</code>]]
+
* [[Cstore|<code>cstore(destaddr, sourceaddr, len, [filename])</code>]]
 
* [[Memcpy|<code>memcpy(dest_addr, source_addr, len)</code>]]
 
* [[Memcpy|<code>memcpy(dest_addr, source_addr, len)</code>]]
 
* [[Memset|<code>memset(dest_addr, val, len)</code>]]
 
* [[Memset|<code>memset(dest_addr, val, len)</code>]]
* [[Peek|<code>peek(addr)</code>]]
+
* [[Peek|<code>peek(addr, [n])</code>]]
* [[Poke|<code>poke(addr, val)</code>]]
+
* [[Peek2|<code>peek2(addr, [n])</code>]]
* [[Reload|<code>reload(dest_addr, source_addr, len, [filename])</code>]]
+
* [[Peek4|<code>peek4(addr, [n])</code>]]
 
* [[Poke|<code>poke(addr, [value,] [...])</code>]]
 
* [[Poke2|<code>poke2(addr, [...])</code>]]
 
* [[Poke4|<code>poke4(addr, [...])</code>]]
  +
* [[Reload|<code>reload(destaddr, sourceaddr, len, [filename])</code>]]
  +
* [[Serial|<code>serial(channel, sourceaddr, size)</code>]]
   
 
== Math ==
 
== Math ==
Line 137: Line 146:
 
* [[Dget|<code>dget(index)</code>]]
 
* [[Dget|<code>dget(index)</code>]]
 
* [[Dset|<code>dset(index, value)</code>]]
 
* [[Dset|<code>dset(index, value)</code>]]
  +
  +
* [[Cstore|<code>cstore(dest_addr, source_addr, len, [filename])</code>]]
  +
* [[Reload|<code>reload(dest_addr, source_addr, len, [filename])</code>]]
   
 
== Coroutines ==
 
== Coroutines ==
   
 
* [[Cocreate|<code>cocreate(func)</code>]]
 
* [[Cocreate|<code>cocreate(func)</code>]]
* [[Coresume|<code>coresume(cor)</code>]]
+
* [[Coresume|<code>coresume(cor, [...])</code>]]
 
* [[Costatus|<code>costatus(cor)</code>]]
 
* [[Costatus|<code>costatus(cor)</code>]]
* [[Yield|<code>yield()</code>]]
+
* [[Yield|<code>yield([...])</code>]]
  +
  +
== Strings ==
  +
 
*[[Split|<code>split(str, [separator, ] [convert_numbers])</code>]]
  +
*[[Sub|<code>sub(str, from, [to])</code>]]
  +
*[[Chr|<code>chr(num)</code>]]
  +
*[[Ord|<code>ord(str, [index])</code>]]
  +
*[[Tonum|<code>tonum(val, [format_flags])</code>]]
  +
*[[Tostr|<code>tostr(val, [usehex])</code>]]
   
 
== Values and objects ==
 
== Values and objects ==
Line 149: Line 170:
 
* [[Setmetatable|<code>setmetatable(tbl, metatbl)</code>]]
 
* [[Setmetatable|<code>setmetatable(tbl, metatbl)</code>]]
 
* [[Getmetatable|<code>getmetatable(tbl)</code>]]
 
* [[Getmetatable|<code>getmetatable(tbl)</code>]]
  +
* <code>[[Rawequal|rawequal(t1, t2)]]</code>
  +
* <code>[[Rawget|rawget(t, n)]]</code>
  +
* <code>[[Rawlen|rawlen(t)]]</code>
  +
* <code>[[Rawset|rawset(t, n, v)]]</code>
  +
* <code>[[Select|select(i, ...)]]</code>
 
* [[Type|<code>type(v)</code>]]
 
* [[Type|<code>type(v)</code>]]
* [[Split|<code>split(str, [separator, ] [convert_numbers])</code>]]
 
* [[Sub|<code>sub(str, from, [to])</code>]]
 
* [[Chr|<code>chr(num)</code>]]
 
* [[Ord|<code>ord(str, [index])</code>]]
 
* [[Tonum|<code>tonum(str)</code>]]
 
* [[Tostr|<code>tostr(val, [usehex])</code>]]
 
   
 
See also [[Lua]], [[Strings]], [[Tables]], [[Metatables]].
 
See also [[Lua]], [[Strings]], [[Tables]], [[Metatables]].
Line 161: Line 181:
 
== Time ==
 
== Time ==
   
* [[Time|<code>time()</code>]]
+
* [[Time|<code>time()</code>]] (alias: <code>[[Time|t()]]</code>)
  +
See also [[Stat#.7B80.E2.80.A685.2C90.E2.80.A695.7D Time of day|Stat: Time of Day]]
   
 
== System ==
 
== System ==
Line 167: Line 188:
 
* [[Menuitem|<code>menuitem(index, [label, callback])</code>]]
 
* [[Menuitem|<code>menuitem(index, [label, callback])</code>]]
 
* [[Extcmd|<code>extcmd(cmd)</code>]]
 
* [[Extcmd|<code>extcmd(cmd)</code>]]
  +
* <code>[[Run|run([breadcrumb])]]</code>
   
 
== Debugging ==
 
== Debugging ==

Revision as of 07:52, 5 March 2022

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

See also Stat: Mouse and Keyboard

Sound

See also Stat: PCM (undocumented)

Map

Memory

Math

See also Math.

Cartridge data

Coroutines

Strings

Values and objects

See also Lua, Strings, Tables, Metatables.

Time

See also Stat: Time of Day

System

Debugging

See also