I'm a novice at Lua, so forgive me if the answe to this is very obvious! I'm using the delightful lua-state-machine (
https://github.com/kyleconroy/lua-state-machine) and the hump.class (
https://github.com/vrld/hump) libraries, although I tried the same code with a different class library and it did the same thing so I suspect the issue is not necessarily down to a library, but to how I'm combining them.
I create a class:
Code: Select all
Actor = Class {
x = 0,
y = 0,
state = machine.create( ... )
}
actors = {}
cow = Actor()
moon = Actor()
table.insert(actors, cow)
table.insert(actors, moon)
I then change the state of one of the instances in my love.mousepressed() function:
Code: Select all
for i,actor in ipairs(actors)
if actor.x == mouseX and actorY == mouseY then
actor.state:jump()
end
then
At this point, both instances switch to the state 'jumping', even though only one of them was clicked. Is this due to some sort of interaction between the state machine and the class, or is it an issue in my for loop? Can I have a separate state machine per instance?