SplitScript reference / Language / let
let
keyword
let name = expression or let name
Declares an inferred variable.
Bindings are mutable and their types are inferred bidirectionally from initializers, assignments, and uses. 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 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()