APIReference: Difference between revisions

From Pico-8 Wiki
Jump to navigation Jump to search
imported>Dddaaannn
(API reference master article)
 
imported>Dddaaannn
No edit summary
Line 1: Line 1:
An API is a function provided by Pico-8 that you can call from a cartridge's source code. You can also call API functions from the Pico-8 [[CommandPrompt|command prompt]], using function syntax.
An API is a function provided by Pico-8 that you can call from a cartridge's source code. You can also call API functions from the Pico-8 [[CommandPrompt|command prompt]], using function syntax.
== Calling APIs ==


Some APIs 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.
Some APIs 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.
Line 23: Line 25:
== 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|<nowiki>_init()</nowiki>]]
Line 29: Line 31:
* [[Draw|<nowiki>_draw()</nowiki>]]
* [[Draw|<nowiki>_draw()</nowiki>]]


If your code doesn't use the game loop, you can call this function to copy graphics 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|<nowiki>flip()</nowiki>]]
Line 35: Line 37:
== Graphics ==
== Graphics ==


* [[Pget|<nowiki>pget(x, y)</nowiki>]]
* [[Camera|<nowiki>camera([x,] [y])</nowiki>]]
* [[Pset|<nowiki>pset(x, y, [c])</nowiki>]]
* [[Circfill|<nowiki>circfill(x, y, r, [col])</nowiki>]]
 
* [[Circ|<nowiki>circ(x, y, r, [col])</nowiki>]]
* [[Sget|<nowiki>sget(x, y)</nowiki>]]
* [[Clip|<nowiki>clip([x,] [y,] [w,] [h])</nowiki>]]
* [[Sset|<nowiki>sset(x, y, [c])</nowiki>]]
* [[Cls|<nowiki>cls()</nowiki>]]
 
* [[Color|<nowiki>color(col)</nowiki>]]
* [[Cursor|<nowiki>cursor(x, y)</nowiki>]]
* [[Fget|<nowiki>fget(n, [f])</nowiki>]]
* [[Fget|<nowiki>fget(n, [f])</nowiki>]]
* [[Fset|<nowiki>fset(n, [f,] [v])</nowiki>]]
* [[Fset|<nowiki>fset(n, [f,] [v])</nowiki>]]
 
* [[Line|<nowiki>line(x0, y0, x1, y1, [col])</nowiki>]]
* [[Palt|<nowiki>palt([c,] [t])</nowiki>]]
* [[Pal|<nowiki>pal([c0,] [c1,] [p])</nowiki>]]
* [[Pget|<nowiki>pget(x, y)</nowiki>]]
* [[Print|<nowiki>print(str, [x,] [y,] [col])</nowiki>]]
* [[Print|<nowiki>print(str, [x,] [y,] [col])</nowiki>]]
* [[Cursor|<nowiki>cursor(x, y)</nowiki>]]
* [[Pset|<nowiki>pset(x, y, [c])</nowiki>]]
 
* [[Rectfill|<nowiki>rectfill(x0, y0, x1, y1, [col])</nowiki>]]
* [[Clip|<nowiki>clip([x,] [y,] [w,] [h])</nowiki>]]
* [[Color|<nowiki>color(col)</nowiki>]]
* [[Camera|<nowiki>camera([x,] [y])</nowiki>]]
 
* [[Cls|<nowiki>cls()</nowiki>]]
 
* [[Circ|<nowiki>circ(x, y, r, [col])</nowiki>]]
* [[Circfill|<nowiki>circfill(x, y, r, [col])</nowiki>]]
 
* [[Line|<nowiki>line(x0, y0, x1, y1, [col])</nowiki>]]
 
* [[Rect|<nowiki>rect(x0, y0, x1, y1, [col])</nowiki>]]
* [[Rect|<nowiki>rect(x0, y0, x1, y1, [col])</nowiki>]]
* [[Rectfill|<nowiki>rectfill(x0, y0, x1, y1, [col])</nowiki>]]
* [[Sget|<nowiki>sget(x, y)</nowiki>]]
 
* [[Pal|<nowiki>pal([c0,] [c1,] [p])</nowiki>]]
* [[Palt|<nowiki>palt([c,] [t])</nowiki>]]
 
* [[Spr|<nowiki>spr(n, x, y, [w,] [h,] [flip_x,] [flip_y])</nowiki>]]
* [[Spr|<nowiki>spr(n, x, y, [w,] [h,] [flip_x,] [flip_y])</nowiki>]]
* [[Sset|<nowiki>sset(x, y, [c])</nowiki>]]
* [[Sspr|<nowiki>sspr(sx, sy, sw, sh, dx, dy, [dw,] [dh,] [flip_x,] [flip_y])</nowiki>]]
* [[Sspr|<nowiki>sspr(sx, sy, sw, sh, dx, dy, [dw,] [dh,] [flip_x,] [flip_y])</nowiki>]]


Line 70: Line 62:


* [[Add|<nowiki>add(t, v)</nowiki>]]
* [[Add|<nowiki>add(t, v)</nowiki>]]
* [[All|<nowiki>all(t)</nowiki>]]
* [[Del|<nowiki>del(t, v)</nowiki>]]
* [[Del|<nowiki>del(t, v)</nowiki>]]
* [[All|<nowiki>all(t)</nowiki>]]
* [[Foreach|<nowiki>foreach(t, f)</nowiki>]]
* [[Foreach|<nowiki>foreach(t, f)</nowiki>]]
* [[Pairs|<nowiki>pairs(t)</nowiki>]]
* [[Pairs|<nowiki>pairs(t)</nowiki>]]
Line 82: Line 74:
== Sound ==
== Sound ==


* [[Music|<nowiki>music([n,] [fade_len,] [channel_mask])</nowiki>]]
* [[Sfx|<nowiki>sfx(n, [channel,] [offset])</nowiki>]]
* [[Sfx|<nowiki>sfx(n, [channel,] [offset])</nowiki>]]
* [[Music|<nowiki>music([n,] [fade_len,] [channel_mask])</nowiki>]]


== Map ==
== Map ==


* [[Map|<nowiki>map(cel_x, cel_y, sx, sy, cel_w, cel_h, [layer])</nowiki>]]
* [[Mget|<nowiki>mget(x, y)</nowiki>]]
* [[Mget|<nowiki>mget(x, y)</nowiki>]]
* [[Mset|<nowiki>mset(x, y, v)</nowiki>]]
* [[Mset|<nowiki>mset(x, y, v)</nowiki>]]
* [[Map|<nowiki>map(cel_x, cel_y, sx, sy, cel_w, cel_h, [layer])</nowiki>]]


== Memory ==
== Memory ==


* [[Cstore|<nowiki>cstore(dest_addr, source_addr, len, [filename])</nowiki>]]
* [[Memcpy|<nowiki>memcpy(dest_addr, source_addr, len)</nowiki>]]
* [[Memset|<nowiki>memset(dest_addr, val, len)</nowiki>]]
* [[Peek|<nowiki>peek(addr)</nowiki>]]
* [[Peek|<nowiki>peek(addr)</nowiki>]]
* [[Poke|<nowiki>poke(addr, val)</nowiki>]]
* [[Poke|<nowiki>poke(addr, val)</nowiki>]]
* [[Memcpy|<nowiki>memcpy(dest_addr, source_addr, len)</nowiki>]]
* [[Reload|<nowiki>reload(dest_addr, source_addr, len, [filename])</nowiki>]]
* [[Reload|<nowiki>reload(dest_addr, source_addr, len, [filename])</nowiki>]]
* [[Cstore|<nowiki>cstore(dest_addr, source_addr, len, [filename])</nowiki>]]
* [[Memset|<nowiki>memset(dest_addr, val, len)</nowiki>]]


== Math ==
== Math ==


* [[Max|<nowiki>max(x, y)</nowiki>]]
* [[Abs|<nowiki>abs(x)</nowiki>]]
* [[Min|<nowiki>min(x, y)</nowiki>]]
* [[Mid|<nowiki>mid(x, y, z)</nowiki>]]
* [[Flr|<nowiki>flr(x)</nowiki>]]
* [[Cos|<nowiki>cos(x)</nowiki>]]
* [[Sin|<nowiki>sin(x)</nowiki>]]
* [[Atan2|<nowiki>atan2(dx, dy)</nowiki>]]
* [[Atan2|<nowiki>atan2(dx, dy)</nowiki>]]
* [[Sqrt|<nowiki>sqrt(x)</nowiki>]]
* [[Abs|<nowiki>abs(x)</nowiki>]]
* [[Rnd|<nowiki>rnd(x)</nowiki>]]
* [[Srand|<nowiki>srand(x)</nowiki>]]
* [[Band|<nowiki>band(x, y)</nowiki>]]
* [[Band|<nowiki>band(x, y)</nowiki>]]
* [[Bnot|<nowiki>bnot(x)</nowiki>]]
* [[Bor|<nowiki>bor(x, y)</nowiki>]]
* [[Bor|<nowiki>bor(x, y)</nowiki>]]
* [[Bxor|<nowiki>bxor(x, y, )</nowiki>]]
* [[Bxor|<nowiki>bxor(x, y, )</nowiki>]]
* [[Bnot|<nowiki>bnot(x)</nowiki>]]
* [[Cos|<nowiki>cos(x)</nowiki>]]
* [[Flr|<nowiki>flr(x)</nowiki>]]
* [[Max|<nowiki>max(x, y)</nowiki>]]
* [[Mid|<nowiki>mid(x, y, z)</nowiki>]]
* [[Min|<nowiki>min(x, y)</nowiki>]]
* [[Rnd|<nowiki>rnd(x)</nowiki>]]
* [[Shl|<nowiki>shl(x, y)</nowiki>]]
* [[Shl|<nowiki>shl(x, y)</nowiki>]]
* [[Shr|<nowiki>shr(x, y)</nowiki>]]
* [[Shr|<nowiki>shr(x, y)</nowiki>]]
* [[Sin|<nowiki>sin(x)</nowiki>]]
* [[Sqrt|<nowiki>sqrt(x)</nowiki>]]
* [[Srand|<nowiki>srand(x)</nowiki>]]


== Cartridge data ==
== Cartridge data ==

Revision as of 01:26, 6 June 2016

An API is a function provided by Pico-8 that you can call from a cartridge's source code. You can also call API functions from the Pico-8 command prompt, using function syntax.

Calling APIs

Some APIs 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

Tables

Input

Sound

Map

Memory

Math

Cartridge data

Coroutines

Values and objects

Debugging

See also