Skip to main content

States

auto state Closed
on enter
business.open = false
end
end

state Open
on enter
business.open = true
end
on building.visitorEntered
business.visitors += 1
end
on exit
log("closing, {business.visitors} visitors today")
end
end
  • A state holds event handlers, timer handlers, on enter and on exit.
  • auto state is the starting state; a script has at most one. In a new instance its on enter runs in the start transaction (Lifecycle). This way a business that starts closed has business.open == false, whatever the contract's default.
  • Handlers outside any state belong to the empty state. A script with no states at all is valid.
  • An event goes to the handler in the current state, or else to the one in the empty state; if neither exists, it is ignored. An instance takes the same event at most once.
  • enter and exit are written only inside a state; ready and migrate only at the script's level.

goto​

  • goto Name moves to another state. A goto to the current state does nothing: a repeated decision does not run the entry again.
  • Moving on runs, in order: the old state's on exit → the move → the new state's on enter. All of it is in the current transaction, and the handler goes on in the new state after the goto.
  • goto is not allowed inside on enter and on exit, nor in anything they call; the compiler follows the calls to check.
  • If exit or enter fails, the whole transaction is undone and the state stays as it was; then the error policy applies.