(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> |
||
⚫ | |||
* [[Pairs|<code>pairs(t)</code>]] |
* [[Pairs|<code>pairs(t)</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( |
+ | * [[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>]] |
− | * [[ |
+ | * [[Peek2|<code>peek2(addr, [n])</code>]] |
− | * [[ |
+ | * [[Peek4|<code>peek4(addr, [n])</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 == |
||
+ | |||
⚫ | |||
+ | *[[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>]] |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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
camera([x,] [y])
circ(x, y, r, [col])
circfill(x, y, r, [col])
oval(x0, y0, x1, y1, [col])
ovalfill(x0, y0, x1, y1, [col])
clip([x,] [y,] [w,] [h])
cls([col])
color(col)
cursor([x,] [y,] [col])
fget(n, [f])
fillp([pat])
fset(n, [f,] [v])
line(x0, y0, x1, y1, [col])
pal([c0,] [c1,] [p])
palt([c,] [t])
pget(x, y)
print(str, [x,] [y,] [col])
pset(x, y, [c])
rect(x0, y0, x1, y1, [col])
rectfill(x0, y0, x1, y1, [col])
sget(x, y)
spr(n, x, y, [w,] [h,] [flip_x,] [flip_y])
sset(x, y, [c])
sspr(sx, sy, sw, sh, dx, dy, [dw,] [dh,] [flip_x,] [flip_y])
tline(x0, y0, x1, y1, mx, my, [mdx,] [mdy])
See also Graphics.
Tables
add(t, v, [i])
all(t)
count(t, [v])
del(t, v)
deli(t, i)
foreach(t, f)
ipairs(t)
pack(...)
pairs(t)
unpack(t, [i], [j])
next(t, [key])
Input
See also Stat: Mouse and Keyboard
Sound
See also Stat: PCM (undocumented)
Map
Memory
cstore(destaddr, sourceaddr, len, [filename])
memcpy(dest_addr, source_addr, len)
memset(dest_addr, val, len)
peek(addr, [n])
peek2(addr, [n])
peek4(addr, [n])
poke(addr, [value,] [...])
poke2(addr, [...])
poke4(addr, [...])
reload(destaddr, sourceaddr, len, [filename])
serial(channel, sourceaddr, size)
Math
abs(x)
atan2(dx, dy)
band(x, y)
bnot(x)
bor(x, y)
bxor(x, y)
ceil(x)
cos(x)
flr(x)
lshr(num, bits)
max(x, y)
mid(x, y, z)
min(x, y)
rnd(x)
rotl(num, bits)
rotr(num, bits)
sgn(x)
shl(x, y)
shr(x, y)
sin(x)
sqrt(x)
srand(x)
See also Math.
Cartridge data
Coroutines
Strings
split(str, [separator, ] [convert_numbers])
sub(str, from, [to])
chr(num)
ord(str, [index])
tonum(val, [format_flags])
tostr(val, [usehex])
Values and objects
setmetatable(tbl, metatbl)
getmetatable(tbl)
rawequal(t1, t2)
rawget(t, n)
rawlen(t)
rawset(t, n, v)
select(i, ...)
type(v)
See also Lua, Strings, Tables, Metatables.
Time
See also Stat: Time of Day
System
Debugging
assert(cond, [message])
printh(str, [filename], [overwrite])
stat(n)
stop()
(undocumented)trace()
(undocumented)