SplitScript reference / Language / let
let
keyword
let pattern = expression or let name
Declares an inferred variable.
Bindings are mutable and their types are inferred bidirectionally from initializers, assignments, and uses. An initialized local or top-level declaration may use an irrefutable binding pattern to project several names from its value; the initializer is evaluated once and an annotation after the pattern describes that complete incoming value. An initialized top-level binding is module state: its initializer runs exactly once, before setup. It may allocate and call synchronous pure helpers, but it must be closed: it cannot read or write another global, observe settings, timer, process, or state context, or suspend. A bare top-level let remains a single name and instead gets its lifetime from its direct lifecycle initializer: onAttach creates attachment-scoped state that is cleared on detach, while onStart creates attempt-scoped (or run-scoped) state that is cleared after onReset. The lifecycle initializer must assign it on every completing path.
Examples
Infer a local type
let retryDelay = 30
Keep an attachment-discovered value
let module
state "game.exe" {
level: u32 = process.read(module.address)?;
}
onAttach {
module = await process.mainModule()
}
Compute module state once
let retryDelay = defaultDelay()
Combine patterns while sharing one binding
return match side {
Side.Left(value) | Side.Right(value) => value,
Side.Idle => 0,
}