-
Notifications
You must be signed in to change notification settings - Fork 0
sub
ffredyk edited this page Jul 23, 2026
·
1 revision
Shared (Atomic) / Arithmetic
Binary — <shared|number> sub <number>.
<shared> sub <number> // atomic decrement
<number> sub <number> // regular subtraction
Dual-purpose subtraction command:
- On Shared variable: performs an atomic decrement. Thread-safe from any scheduler. Returns the new value.
-
On regular number: performs standard subtraction (same as
-). Returns the difference.
- Shared: uses atomic CAS loop to decrement. Indivisible operation.
- Number: delegates to standard
-implementation.
shared _ammo = 30;
_ammo sub 1; // atomic decrement — 29
_ammo sub 5; // atomic subtract 5 — 24shared _availableSlots = 10;
// Try to acquire a slot:
_availableSlots sub 1;
if (get _availableSlots < 0) then {
_availableSlots add 1; // give back — no slots available
systemChat "No slots";
};_result = 10 sub 3; // 7 (same as 10 - 3)shared _counter = 10;
_counter sub 1; // ATOMIC — correct
_counter = get _counter - 1; // NOT atomic — race condition!- On Shared: Fully atomic. Thread-safe from any scheduler.
- On Number: Standard computation. Thread-safe for value types.
- add — atomic add
- get — atomic read
- compareSwap — atomic CAS
- - — standard subtraction
- 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