AimForge DOCS
Pricing Login
docs / api / state

State & persistence

AimForge gives you three layers of persistent storage. Each has a different scope and lifetime — pick the right one for the job.

state — per-script, per-frame

The state object persists frame-to-frame within a single script. Members survive script reloads and program restarts, but are scoped to this script — other scripts in the same pipeline cannot read them.

if (!isset(state.history)) {
  state.history = [];
}
state.history = append(state.history, x);
if (len(state.history) > 60) {
  state.history = pop(state.history, len(state.history) - 60);
}

Use state for PID accumulators, smoothing filters, frame counters, debug history — anything that needs to be remembered across frames within a single script.

shared — pipeline-wide

The shared object is visible to every script in the current pipeline. It survives single-script changes, but is reset when the pipeline configuration changes or capture restarts.

// In script A:
shared.lastTargetSeen = time;

// In script B:
if (time - shared.lastTargetSeen < 0.5) {
  // recent target — be more aggressive
}

Use shared for cross-script coordination — for example, an upstream "detection enhancer" script writing flags that downstream aim/fire scripts read.

settings — GUI control values

The settings object holds values set by GUI controls (sliders, dropdowns, etc.). It's read-only at runtime — values are persisted to a preset .ini file and loaded on startup.

//!gui:slider var=strength label="Aim Strength" min=0 max=1 default=0.5

x = x * settings.strength;

To write a settings.* value programmatically (e.g. from a button handler), use setSetting():

//!gui:button label="Reset" func="resetStrength"

function resetStrength() {
  setSetting("strength", 0.5);
  return 0;
}

Persistent disk storage

For values that need to survive across pipeline changes — high scores, learned offsets, etc. — use save() and load(). Values are serialized to the active preset's .ini file.

if (!isset(state.maxDistance)) {
  state.maxDistance = load("maxDistance");
  if (state.maxDistance == null) {
    state.maxDistance = 0;
  }
}

if (distance > state.maxDistance) {
  state.maxDistance = distance;
  save("maxDistance", distance);
}

Checking for existence

isset() returns 1 if a variable has been initialized, 0 otherwise. Use it to guard one-time setup:

if (!isset(state.startTime)) {
  state.startTime = time;
}

Choosing between state and shared

Use state for... Use shared for...
Filter history (EMA, PID accumulators) Flags read by other scripts
Per-script frame counters Cross-script coordinated state
Local debug values Values that should survive a single script reload