# 27.1: a machine's field changes only by a transition in its table import "ludic.base" program MachineFieldWritten { enum Mood { Calm, Wary } property Deer { mood: Mood = Mood.Calm, fear: int = 0 } state Herd { deer: Table = null } action Spook { @Target who: int = -1 } action Shout { loud: int = 1 } property DeerStep { from: Mood = Mood.Calm to: Mood = Mood.Calm on: string = "" guard: fn(Row, Herd) -> bool = null enter: fn(Row, Herd) -> void = null } @Machine(Deer.mood) registry DeerSteps of DeerStep function deer_afraid(r: Row, h: Herd) -> bool { return r.rec.fear > 1 } def DeerSteps startled { from: Mood.Calm, to: Mood.Wary, on: "Spook" } def DeerSteps settles { from: Mood.Wary, to: Mood.Calm, guard: fn deer_afraid } function calm_all(h: mut Herd) -> void { let d = tb_rec(h.deer, 0) d.mood = Mood.Calm } entry { print(1) } }