Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

member data is not stateful #6

Open
cljnnn opened this issue Nov 4, 2019 · 1 comment
Open

member data is not stateful #6

cljnnn opened this issue Nov 4, 2019 · 1 comment

Comments

@cljnnn
Copy link

cljnnn commented Nov 4, 2019

Hi, I am using this wonderful component, thank you for sharing.

I have a problem. Let's say, I have a state A. push A named A1 (self.name is set to A1 when enteredState), push A named A2, do pop I should get back to state A named A1, but actually It's still A2.

Could you please give me some help?

local class    = require 'middleclass'
local Stateful = require 'stateful'

local Enemy = class('Enemy')
Enemy:include(Stateful)

function Enemy:speak()
end

local A = Enemy:addState('A')

-- overriden function
function A:enteredState(name)
    self.name = name
    print( 'enteredState ' .. name )
end

function A:speak()
  print( 'I am ' .. self.name )
end

local peter = Enemy:new()

peter:pushState('A', 'A1') -- enteredState A1
peter:speak() -- I am A1
peter:pushState('A', 'A2') -- enteredState A2
peter:speak() -- I am A2
peter:popState()
peter:speak() -- I am A2, expect 'I am A1'
@mikelyons
Copy link

I am also having some issues similar to this, did you ever get a resolution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants