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

max

Category

Arithmetic

Arity

Binarya max b.

<number> max <number>

Description

Returns the larger of two numbers. If equal, returns that value. Auto-unwraps shared values before comparing.

How It Works

Compares two double values and returns the greater one. Equivalent to Math.Max(a, b). The host re-registers max with shared-value unwrapping.

Usage

Clamp lower bound

_hp = _hp max 0;              // never below 0
_damage = (_incoming - _armor) max 0;  // no negative damage

Simple maximum

_best = _scoreA max _scoreB;
_budget = _requested max _minimum;

Full clamp (with min)

// Clamp _value between _low and _high
_clamped = (_value max _low) min _high;

// Example: clamp health to [0, 100]
_hp = ((_hp + _heal) max 0) min 100;

Array reduction (find maximum)

_findMax = {
    params ["_arr"];
    private _max = _arr select 0;
    { _max = _max max _x } forEach _arr;
    _max
};
_result = [3, 7, 2, 9] call _findMax;  // 9

Thread Safety

ReadOnly — pure computation, no side effects. Safe from any scheduler.

See Also

  • min — smaller of two numbers
  • > — greater-than comparison
  • select — array element access

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