onCollision scenes variables problem

Hello everyone,

I recently started using the Corona SDK and encountered the following problem

In my collision function(listener) i have the following script:

 if((event.object1.myName=="enemy" and event.object2.myName=="bullet") or (event.object1.myName=="bullet" and event.object2.myName=="enemy")) then if(event.object1.myName=="enemy") then e = event.object1 b = event.object2 else e = event.object2 b = event.object1 end if(e.y \< 0 or e.x \< 0 or e.x \> display.contentWidth) then elseif(b.c == 0) then b.c = 1 stats\_hit = stats\_hit+1 if(spawn\_time ~= 400) then spawn\_time = 5000-(stats\_hit\*100) end transition.pause( e ) print("Enemy HP before hit: " .. e.hp) e.hp = e.hp-1 print("Enemy HP after hit: " .. e.hp) e:applyForce(0,-50,e.x,e.y) local function punch(event) transition.resume( e ) end timer.performWithDelay( 100, punch ) print("collision") if(e.hp == 0) then print("Enemy ID hit: " .. e.id) transition.cancel( e ) event.object1:removeSelf() event.object1.myName=nil event.object2:removeSelf() event.object2.myName=nil e.hp = nil stats\_score = stats\_score + 10 stats\_enemies = stats\_enemies + 1 numHit = numHit + 1 print ("numhit "..numHit) createStain(e.x, e.y, "big") else createStain(e.x, e.y, "small") b:removeSelf() b.myName = nil end end end

where numHit is the count of the enemies that have collided with a bullet.

The problem is that when the game goes to another scene and comes back to this one, the value of the variable numHit is not reset, even if I make it nill in stage:create

The scene:create function is only fired once - the first time the scene is called.

You’ll need to reset numHit in the ‘will’ phase of scene:show

I think.

i have it there as well, but it still doesn’t get reset

The scene:create function is only fired once - the first time the scene is called.

You’ll need to reset numHit in the ‘will’ phase of scene:show

I think.

i have it there as well, but it still doesn’t get reset