Add

From Director Online Wiki
Jump to: navigation, search
add
Type: method
Version:  ?
Language: Lingo
Dependencies: none
Links/Related
push (JavaScript), sort

Adds a value to a linear list in its proper order (if the list is sorted) or at the end (if the list is not sorted). The "proper order" is treated in more detail at the entry for sort().

If you are working with unsorted lists, the append() method is faster.

If you use append() or setAt() on a sorted list, the list becomes unsorted and subsequent use of add will place the new values at the end of the list.

Syntax

from MX 2004 Documentation

linearList.add(value)

Verbose Syntax

add(linearList, value)

Examples

vSpades = []
vSpades.sort()
vSpades.add(3)
vSpades.add("Ace") -- will be sorted after numbers
vSpades.add(2)     -- will be placed before 3
put vSpades
-- [2, 3, "Ace"]
vSpades.append(5)  -- will be placed at the end, and will unsort the list
vSpades.add(4)     -- will be placed at the end as the list is now unsorted
put vSpades
-- [2, 3, "Ace", 5, 4]

See also