API Reference › Annotations › @OnStart
annotation

@OnStart

@OnStart handler Name { … }

@OnStart pins a handler to the program's boot moment: it runs exactly once when the program starts, before the per-frame phases begin, instead of being placed in a recurring phase. Use it for one-time setup — spawning the initial world, seeding program vars, loading a scene. It overrides the handler's phase, so you write @OnStart handler Name { … } rather than handler Name phase Start and get the same once-at-boot placement through the annotation channel. Its shutdown counterpart is @OnQuit; add @Public to also emit a program_start event other modules can hook.

Example

program BootHook {
  property Health { current: int = 0, maximum: int = 100 }
  model Player { Health }

  var elapsed_frames: int = 0

  @OnStart handler CreateWorld {                     # runs once at boot
    spawn Player { Health { current: 100, maximum: 100 } }
    elapsed_frames = 0
  }

  handler CountFrames phase Update { elapsed_frames = elapsed_frames + 1 }
}
← All symbols