Now I am using the middle class LUA library after some problems, and I have a situation that I cannot understand.
Say I have my class: EDIT: Had a typo: here are the actual functions
require "middleclass" weaponCanon2 = class("weaponCanon2") function weaponCanon2:onWeaponCollision(event) if (event.phase == "began") then if (event.other.name ~= "ground") then self.canonBall.inAir = false end end end function weaponCanon2:initialize(atX, atY, inGroup) self.name = "some value" self.someObject:addEventListener("touch", **weaponCanon2.onWeaponCollision**) ... end
When I do this, each variable, such as self.name in the above example, is now zero. I believe this is because my function:
function weaponCanon2:onWeaponCollision(event) ... end
Then setting the collision event variable, for example self.collisionEvent = weaponCanon2.onWeaponCollision, is not the same thing. I am not 100% sure what the difference is between: and. the operator is in LUA terms, but this gives me different problems.
Now another example: I have a reset function. The timer goes off and then calls the reset function. If I do this:
timer.performWithDelay(100, weaponCanon2.resetShot, 1)
Then, in 100 ms, he will call the weaponCAnon2.resetShot 1 time. When he does this, all my variables are self.name, etc. Equal to zero. Now, if I create my class:
require("weaponCanon2") local canon = weaponCanon2:new("someName") canon:saveInstance(canon)
and then back to my class file:
function saveInstance(value) self.instance = value end
Now I can use this timer, calling it like this:
timer.performWithDelay(100, function() self.instance:resetShot(); end, 1)
This will work without any of my member variables (self.name) equal to == equal to zero. Is there a better / easier way to do this when using your library or in LUA?
Sorry for being unclear. I am having problems thinking about this problem and explaining that it is very difficult.
Thanks for the help,
-d