state_machine: include prev_state_name

This commit is contained in:
Bill Hilbert 2023-12-14 20:54:05 -05:00
parent 2d0abbd021
commit ca49753375

View File

@ -33,6 +33,7 @@ local state_machine = class({
function state_machine:new(states, start_in_state)
self.states = states or {}
self.current_state_name = ""
self.prev_state_name = ""
self.reset_state_name = start_in_state or ""
self:reset()
end
@ -151,6 +152,7 @@ end
function state_machine:set_state(name, reset)
if self.current_state_name ~= name or reset then
self:_call("exit")
self.prev_state_name = self.current_state_name
self.current_state_name = name
self:_call_and_transition("enter", self)
end