count
count <iterable>
The number of elements in an iterable.
Arguments
Returns
An int — the count of elements. An empty iterable counts 0.
Examples
after command (say) {
do "say There are [count [words "one two three"]] words."
}
[count ...] evaluates to 3, so the mob says "There are 3 words."
after command (say) {
require [gt [count [creatures $self]] 1]
do "say It is crowded in here."
}
[count [creatures $self]] is the number of living creatures in the owner's
room. The require guard runs the rest of the handler
only when more than one creature is present. Counting an
iterable consumes it; the value is the number of elements it
would have yielded.
See also
empty— a cheaper present-or-not test when you only need to know whether anything is there.nth,first— read individual elements.- Iterables and iterables · Types