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

get

Category

HashMap / Shared / Array

Arity

Unary or Binary, depending on context.

// Unary: on Shared
get <shared>

// Binary: on HashMap or Array
<hashmap> get <key>
<array> get <index>     // same as select
<shared> get <void>      // unary read

Description

Multi-purpose retrieval command:

  • HashMap: _map get _key — returns the value for the given key, or nil if not found.
  • Shared: get _sharedVar — atomically reads the current value of a shared (atomic) variable.
  • Array: _arr get _index — equivalent to select, returns element at index (nil if out of range).

How It Works

The host dispatches based on the left operand type:

  • HashMap → dictionary lookup.
  • Shared → atomic read of the underlying value.
  • Array → delegate to select behavior.

Usage

HashMap get

_map = createHashMapFromArray ["hp", 100, "name", "player"];
_hp = _map get "hp";           // 100
_name = _map get "name";       // "player"
_missing = _map get "xyz";     // nil

Shared (atomic) get

shared _counter = 0;
_counter add 1;
_val = get _counter;           // read current value atomically

Array get (same as select)

_arr = [10, 20, 30];
_arr get 0;                    // 10
_arr get 99;                   // nil (out of range)

Safe hashmap access

_val = _map get _key;
if (isNil "_val") then {
    systemChat f"Key '{_key}' not found";
};

Thread Safety

  • HashMap get: ReadOnly on the hashmap. Safe from owning scheduler.
  • Shared get: Atomic read — thread-safe from any scheduler.
  • Array get: ReadOnly. Safe from owning scheduler.

See Also

  • set — store value
  • select — array element (same as array get)
  • createHashMap — create empty hashmap
  • shared — declare shared variable

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