Add: Difference between revisions

From Pico-8 Wiki
Jump to navigation Jump to search
imported>Dddaaannn
No edit summary
imported>Dddaaannn
(add() returns the object being added.)
Line 8: Line 8:


Specifically, <code>add()</code> looks for an element at index 1, increments the index until it finds no element assigned (<code>nil</code>), then assigns the new value to that unused index.
Specifically, <code>add()</code> looks for an element at index 1, increments the index until it finds no element assigned (<code>nil</code>), then assigns the new value to that unused index.
The <code>add()</code> function returns the object being added. (You can ignore this return value.)


== Examples ==
== Examples ==

Revision as of 19:56, 28 October 2017

add( tbl, v )
Adds a element to the end of a sequence in a table.
tbl
The table.

v
The value to add.

The add() function appends an element to the end of a sequence in a table.

Specifically, add() looks for an element at index 1, increments the index until it finds no element assigned (nil), then assigns the new value to that unused index.

The add() function returns the object being added. (You can ignore this return value.)

Examples

t = {1, 3, 5}
add(t, 7)  -- t = {1, 3, 5, 7}
add(t, 9)  -- t = {1, 3, 5, 7, 9}

See also