Add: Difference between revisions

From Pico-8 Wiki
Jump to navigation Jump to search
imported>Dddaaannn
(New reference article: add)
 
imported>Dddaaannn
No edit summary
Line 19: Line 19:


* [[Lua]]
* [[Lua]]
* [[Table]]
* [[Tables]]
* [[Add|add]]
* [[Add|add]]
* [[All|all]]
* [[All|all]]

Revision as of 05:06, 3 January 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.

Examples

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

See also