Lists
Lists are much like variables, but they hold more than one value.
Defining Lists
Variables are defined by
@{list name} = {list items value}
- Valid list names consist of alphabetic ascii characters only
- list names are case insensitive
- lists can store any number of values produced by functions or constant list definitions.
Example:
$bar=pool(4d6);
sets the list $bar to the individual results of 4 single dice rolls.
Using lists
To use a list, you can reference it by using
@{list name}
wherever the values are needed.
Example:
print @bar ;
prints the list @bar to the output
To get a single list items, use square brackets to give the index number of the item you want:
@{list name}[{index}]
- indices must be numeric
- Indices start with 1! 1)
- if you specify an index higher than the number of list items, this is an error.
Example:
print @bar[2] ;
prints the second item of list @bar to the output
If a list index describes a roll result, for example d6:2, only the result (2) is used as index. 2)
Constant list definitions
To directly set the values of a list, use square brackets:
[ one, two, three ]
This can be used everywhere you need list values, even standalone (in the rare case you need a list on the stack).
Example:
$bar=[1, 2, 3];
sets the list $bar to the values 1, 2 and 3
Counting lists
To get the number of list items, use
count ( @list );