removeSelf function not firing

Hey all,

I have the following code in my lua file, which defines the gameOver function I am calling later in the script.

function gameOver()  
 gameOverText = display.newText("Game Over", 50, 240, native.systemFontBold, 40)  
   
 local function removeGOText()  
 gameOverText:removeSelf()  
 end  
   
 timer.performWithDelay(2000, removeGOText)  
   
 player:removePlayer()  
 Runtime:removeEventListener("enterFrame", runtimeListener)  
 Runtime:removeEventListener("accelerometer", accelerometerCall)  
 Runtime:removeEventListener("touch", touchListener)  
   
 loader:removeAllSprites()  
 localGroup = nil  
 timer.performWithDelay(2000, startOver)  
end  

gameOverText = display.newText fires just fine and displays the text when the player dies.

local function removeGOText and everything below it does NOT fire and I don’t know why. The gameOver text just remains on the screen and the startOver function never works.

Any ideas?
[import]uid: 125387 topic_id: 22833 reply_id: 322833[/import]

My best guess is that you’ve made “gameOverText” a global display object… big no-no… make it local and see if that works. Or, if you need to use it elsewhere for whatever reason, then create a local up-reference above that function.

Also try to make the entire “gameOver” function local. If you’re calling that function “from above” then try to move it (gameOver function) above the function which is calling it. I know it’s not always possible, but basically global anything is bad Lua practice (and bad programming practice in general).

Brent Sorrentino
Ignis Design
[import]uid: 9747 topic_id: 22833 reply_id: 91198[/import]

Thanks for your reply. I changed it to be a local function but it still doesn’t work :frowning: Will keep playing with it to see if I can get this fixed. [import]uid: 125387 topic_id: 22833 reply_id: 91288[/import]

Try [lua]display.remove(gameOverText)[/lua] [import]uid: 71024 topic_id: 22833 reply_id: 91370[/import]