first

first <iterable>

The first element of an iterable.

Arguments

Returns

The first element, or null if the iterable is empty.

Examples

after command (say) {
  do "say The first word is [first [words "alpha beta gamma"]]."
}

[first ...] evaluates to "alpha", so the mob says "The first word is alpha."

after command (say) {
  let target [first [creatures $self]]
  unless [isnull $target]
  do "smile $target"
}

target is bound to the first living creature in the owner's room. The unless guard skips the smile when the room is empty and first returned null instead of a creature.

See also