SplitScript reference / Language / onAttach

onAttach

lifecycle block

onAttach { ... }

Initializes one state-provider attachment.

This action is implicitly suspending and owns attachment-lifetime cancellation for await and retry continuations. It is also an implicit error boundary: postfix ? or throw rejects this attachment, keeps its host process inert until it closes, and never runs onDetach for the incomplete attachment. A bare global assigned on every successful path becomes attachment-scoped and may select conditional state and managed class fields. Attachment-scoped globals are frozen after this action completes. Emulator providers run this action again when a newly discovered game mapping replaces one that disappeared without closing the emulator.

Examples

Use onAttach

onAttach {
    let module = await process.module("GameAssembly.dll")
}
SymbolDescription
stateDeclares process attachment and persistent watched state.
conditional fieldsDeclares fields whose availability follows an ordinary enum value.
awaitWaits for an asynchronous value and yields its result.
retryRetries synchronous fallible work until it succeeds.
?Propagates a T! error.
throwTransfers an error to the nearest failure boundary.
onStateReadyInitializes one committed state snapshot.