Manual:DIL Manual/integerlist
Jump to navigation
Jump to search
integerlist
Type. The keyword is intlist.
il : intlist;
A list of integers, numbered from 0. Declare it as intlist (there is no keyword integerlist). The vals field of an extra description is also an intlist, and so is what weapon_info() gives.
Using it
| Write | What it does |
|---|---|
il := {10, 20, 30}; |
sets the whole list; the values must be constants or macros, not variables |
il.[1] |
the second value; read and write |
length(il) |
how many values it has |
insert(il, i, v); |
puts v in at position i, moving the rest up; i from 0 to length(il)
|
remove(il, i); |
takes out the value at position i
|
il := null; |
empties it |
il := other; |
copies another intlist |
Notes
- An index outside the list fails: reading
il.[5]of a list of three is a failed value (false in every comparison), and assigning to it does nothing. The list doesn't grow by assignment; add values withinsert(il, length(il), v). insert()with a position past the end, andremove()with one outside the list, do nothing.- A new intlist variable is empty. Unlike unit and extra variables, an intlist keeps its values across
wait()andpause. indoesn't work on intlists; walk the list with awhileloop.{...}can't hold variables:{n, 2}is a syntax error. Build such a list withinsert().- An intlist can be a template's argument; from a zone file it's written
{1, 2, 3}.dilcopy()from DIL can't pass lists.
Example
dilbegin integer sumlist(il : intlist);
var
i : integer;
sum : integer;
code
{
i := 0;
sum := 0;
while (i < length(il))
{
sum := sum + il.[i];
i := i + 1;
}
return (sum);
}
dilend
dilbegin listdemo();
external
integer sumlist@ex(il : intlist);
var
il : intlist;
n : integer;
code
{
il := {10, 20, 30};
il.[1] := 25;
insert(il, length(il), 40);
remove(il, 0);
n := sumlist@ex(il);
log("Sum is " + itoa(n));
il := null;
quit;
}
dilend
Builds the list 25, 30, 40 and logs "Sum is 95".