Skip to content
ffredyk edited this page Jul 23, 2026 · 1 revision

count

Category

Array / String

Arity

Unarycount <value>.

count <array>
count <string>

Description

Returns the number of elements in an array, or the number of characters in a string. For nil, returns 0 (SQF compat). Works on both mutable and frozen arrays.

How It Works

  • Array: returns the .Count of the underlying list. O(1).
  • String: returns string.Length (character count). O(1).
  • Nil: returns 0 (Arma SQF compatibility).

Usage

Array length

_arr = [1, 2, 3, 4, 5];
_len = count _arr;                // 5

if (count _enemies == 0) then {
    systemChat "Area clear";
};

String length

_name = "Arma";
_len = count _name;               // 4

if (count _input > 50) then {
    systemChat "Input too long";
};

Loop bounds

for "_i" from 0 to (count _arr - 1) do {
    _elem = _arr select _i;
    process(_elem);
};

Nil guard

_len = count _maybeNil;           // 0 if nil, safe

Thread Safety

ReadOnly — pure query. Safe from any scheduler.

See Also

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally