Skip to content

createHashMapFromArray

ffredyk edited this page Jul 23, 2026 · 1 revision

createHashMapFromArray

Category

HashMap

Arity

UnarycreateHashMapFromArray <array>.

createHashMapFromArray <array>   // [key1, val1, key2, val2, ...]

Description

Creates a new hashmap pre-populated from a flat array of alternating keys and values. The array must have an even number of elements: [key1, val1, key2, val2, ...]. If the array has an odd length, the last key without a value is ignored.

How It Works

Iterates the array in pairs, inserting each (key, value) into a new Dictionary<Value, Value>. The resulting hashmap is mutable and owned by the current scheduler. Duplicate keys: later values overwrite earlier ones.

Usage

Create with initial data

_map = createHashMapFromArray ["a", 1, "b", 2, "c", 3];
_map get "b";                  // 2
_map get "a";                  // 1

Quick config

_settings = createHashMapFromArray [
    "volume", 0.8,
    "music", true,
    "difficulty", "normal"
];

From variables

_name = "player";
_hp = 100;
_alive = true;
_entity = createHashMapFromArray [
    "name", _name,
    "hp", _hp,
    "alive", _alive
];

Duplicate keys

_map = createHashMapFromArray ["key", 1, "key", 2];
_map get "key";                // 2 (later overwrites earlier)

Thread Safety

Not thread-safe. HashMap must be owned by the current scheduler.

See Also

  • createHashMap — create empty hashmap
  • get — retrieve value by key
  • set — store key-value pair

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