-
Notifications
You must be signed in to change notification settings - Fork 0
set
ffredyk edited this page Jul 23, 2026
·
1 revision
HashMap / Array / Shared
Binary — <target> set [key|index, value].
<hashmap> set [key, value]
<array> set [index, value]
<shared> set [nil, value] // write shared value
Multi-purpose assignment command. Packs parameters into an array on the right side:
-
HashMap:
_map set [key, value]— stores a key-value pair. Creates key if not present, overwrites if exists. -
Array:
_arr set [index, value]— sets element at index. Index must be within bounds. -
Shared:
_shared set [nil, value]— writes a value to a shared (atomic) variable. Not atomic — prefer compareSwap for concurrent updates.
The host dispatches based on the left operand type, unpacks the right-side array, and performs the appropriate write operation.
_map = createHashMap;
_map set ["health", 100];
_map set ["name", "player"];
_map set ["health", 75]; // overwrite existing key_arr = [1, 2, 3, 4];
_arr set [0, 99]; // _arr is [99, 2, 3, 4]
_arr set [3, 88]; // _arr is [99, 2, 3, 88]
// Out of bounds → error
_arr set [99, 0]; // ERROR — index out of rangeshared _flag = false;
_flag set [nil, true]; // set shared value (not atomic!)
// Better for concurrent updates:
_flag compareSwap [false, true];_config = createHashMap;
{
_x params ["_key", "_val"];
_config set [_key, _val];
} forEach [
["volume", 0.8],
["music", true],
["difficulty", "normal"]
];- HashMap set: Not thread-safe. HashMap must be owned by current scheduler.
- Array set: Not thread-safe. Array must be owned by current scheduler.
- Shared set: Not atomic. Use compareSwap for concurrent updates.
- get — retrieve value
- pushBack — append to array
- compareSwap — atomic CAS for shared
- createHashMap — create empty hashmap
- Getting Started
- Language Guide
- Type System
- Control Flow
- Functions & Code
- Strings & Text
- Arrays & Collections
- Concurrency
- Promise System
- Thread Safety
- Host API & Embedding
- CLI Tool
- Bytecode Reference
- Multiplayer
- Syntax Sugar
- Optimization Guide
- Benchmarks
- count
- select
- pushBack
- append
- deleteAt
- deleteRange
- resize
- reverse
- sort
- find
- in
- forEach
- freeze
- thaw
- isFrozen
- currentScheduler
- clientOwner
- allSchedulers
- schedulerName
- schedulerExists
- schedulerBudget
- setSchedulerBudget
- fiberCount
- readyFiberCount
- waitingFiberCount
- schedulerLoad
- sendTo