Error: attempt to perform arithmetic on field 'rotation' (a nil value)

Hi everybody,

I am having some problem with an extra scene I am creating for my existing game app.

Basically from the main menu I have created a button which will recall another Game Scene which right now is exactly like the one there is already, but in the future i would like to make this the difficult mode of the game.

When I touch the button I go to this scene and It will play like the other one perfectly, but at the end when I click the reload button for this scene I get this error:

ERROR: Runtime error /gameSceneCrazy.lua:296: attempt to perform arithmetic on field 'rotation' (a nil value) stack traceback: &nbsp;&nbsp; &nbsp;/gameSceneCrazy.lua:296: in function/gameSceneCrazy.lua:295\> &nbsp;&nbsp; &nbsp;?: in function \<?:169\>

Now this is the line It refers to: (295-296)

function animate ( event ) blade1.rotation = blade1.rotation + 15 blade2.rotation = blade2.rotation + 15 end Runtime:addEventListener ( "enterFrame", animate );

And this is the function (169)

composer.gotoScene( "reload", options )

This is the all function when you touch the button:

local okButton = Lib.newSimpleButton(group, "IMG/ok.png", 100, 100); okButton.x, okButton.y = centerX, centerY+20; function okButton:touch(event) if event.phase == "began" then local options ={ effect = "fade", time = 0, params = { myData = 1234 } } composer.gotoScene( "reload", options ) end end

Thank You

Never mind I solved it!

So for anyone having the same problem, you should first check out that the function that animates the rotation is not a local function and then you should just add this line when you leave the scene:

 Runtime:removeEventListener("enterFrame", animate);

Keep coding

Never mind I solved it!

So for anyone having the same problem, you should first check out that the function that animates the rotation is not a local function and then you should just add this line when you leave the scene:

 Runtime:removeEventListener("enterFrame", animate);

Keep coding