Skip to content

createHashMap

ffredyk edited this page Jul 23, 2026 · 1 revision

createHashMap

Category

HashMap

Arity

NularcreateHashMap.

createHashMap

Description

Creates a new empty hashmap (dictionary). HashMaps store key-value pairs with fast O(1) lookup. Keys and values can be of any type. Keys are compared by value — two equal numbers or strings are considered the same key.

How It Works

Allocates a new Dictionary<Value, Value> with the SQ# equality comparer. The hashmap is mutable and owned by the current scheduler.

Usage

Create and populate

_map = createHashMap;
_map set ["health", 100];
_map set ["name", "player"];
_map set ["alive", true];

Read values

_hp = _map get "health";       // 100
_name = _map get "name";       // "player"
_missing = _map get "xyz";     // nil (key not found)

Check key existence

if (!isNil {_map get "health"}) then {
    systemChat f"Health: {_map get "health"}";
};

As configuration store

_config = createHashMap;
_config set ["maxPlayers", 32];
_config set ["difficulty", "hard"];
_config set ["timeLimit", 900];

Nested maps

_player = createHashMap;
_player set ["name", "John"];
_stats = createHashMap;
_stats set ["hp", 100];
_stats set ["xp", 500];
_player set ["stats", _stats];

Thread Safety

Not thread-safe. HashMap must be owned by the current scheduler. Use freeze pattern for cross-scheduler sharing, or transfer ownership with sendTo.

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