local states = { -- Initial state, sets up the plant to full health, then drops to normal state. "start": { { entry = setup_full_health, -- Also needs registering?! initial = true, events = { "tick_day": { next_state = "decreasing" } } } }, -- Plant in normal state, loosing water, and slowly dying. "decreasing": { events = { "tick_day": { { condition = function(self): return self.current_state < 5 end, action = decrease_plant, next_state = "decreasing" }, { -- Plant already dead, current state does not need managing. next_state = "decreasing" } }, "watering": { { next_state = "restoring" } }, "pick_up": { { action = unregister_plant, next_state = "picked_up" } } } }, -- Plant got watered, and is recovering to full health. "restoring": { entry = setup_restore, events = { "tick_day": { { condition = function(self): return self.current_state > 1 end, action = restore_plant, next_state = "restoring" }, { -- Restored to full health, go back to decreasing action = function(self) self.days_left = DAYS_BETWEEN_STATES end, next_state = "decreasing" } } "watering": { { next_state = "restoring" } -- Already restoring, do nothing. } "pick_up": { { action = unregister_plant, next_state = "picked_up" } } } }, "picked_up" : { events = { "drop": { { action = register_plant, next_state = "decreasing" } } } } }