Syntax
Declares a list: values kept in order, with one current element. <name>() reads or writes that element.
NewList <name>.<type>()
NewList <name>()
GLOBAL NewList <name>.<type>()
LOCAL NewList <name>.<type>()
<name>()
<name>().<field>Parts
| <name> | The list's name, with no sigil. It cannot also be the name of a map. |
|---|---|
| <type> | The type of the elements: a short suffix (.i, .f, .d, .s, .q…), a full name (.integer, .string, .float64), or a TYPE name. Without it, the list holds integers. |
| <field> | A field of the current element, for a list of records: foes().hp = 30. |
Good to know
- A new list is empty and has no current element. Reading or assigning
<name>()then stops the program:BASIC list has no current element. Add one first with AddElement(). - Values are converted to the list's type: an integer list stores 20.9 as 20, and
.fis 32-bit (0.1reads back as0.10000000149011612). Use.dfor full precision. NewList names$()is refused at the first use ofnames(). Write the type after a dot:NewList names.s().+=on the current element andINC l()compile into a program that does not start. Writel() = l() + 5.NewListagain on the same name makes a new, empty list. ANewListinside a FUNCTION belongs to that call.- In a program with a
DO … LOOP, a FUNCTION does not see a list declared aboveDO(… is not defined). Declare it withGLOBAL NewList.
Example
NewList scores.i()AddElement(scores())scores() = 10AddElement(scores())scores() = 30FirstElement(scores())AddElement(scores())scores() = 20.9FOREACH scores() Console(Str(ListIndex(scores())) + ": " + Str(scores())) ' 0: 10, then 1: 20, then 2: 30NEXTConsole(Str(ListSize(scores()))) ' 3In the manual : Arrays, lists and maps