Text is not getting removed after clicking

Hi there,

I added a Pause button, before realising that sometimes you can’t tell if it’s paused or not. So I went to add text that says “Paused”, to the right of the pause button. Done.

Now, it isn’t being removed when I unpause the game… even though the display.remove (pauseText) line is there. Repeatedly clicking the button makes new text over the old text (making it bolder).

So I want to remove this text!

It would be even better if I could change the button which says “Pause”, for which the event listener click runs the gamePause function, to “Paused” when it is paused and “Pause” when not paused.
 

Here’s my code:

local function gamePause( event )
    if event.phase == “began” then
        if gamePaused == false then
             physics.pause()
             timer.pause( gameLoopTimer)
             local pauseText = display.newText(“Paused”, display.contentCenterX + 200, 920, native.systemFontBold, 40 )
             gamePaused = true
        elseif gamePaused == true then
             physics.start()
             timer.resume( gameLoopTimer)
             display.remove ( pauseText )
             gamePaused = false
        end
   end
end
 

this is a scoping issue.  this will work

local pauseText = display.newText("Pause", display.contentCenterX + 200, 920, native.systemFontBold, 40 ) pauseText.isVisible = false \<-- remove this to have the button there all the time local function gamePause( event ) if event.phase == "began" then gamePaused = not gamePaused if gamePaused then physics.pause() timer.pause( gameLoopTimer) pauseText:setText("Paused") else physics.start() timer.resume( gameLoopTimer) pauseText:setText("Pause") end pauseText.isVisible = gamePaused \<-- remove this to have the button there all the time end end

this is a scoping issue.  this will work

local pauseText = display.newText("Pause", display.contentCenterX + 200, 920, native.systemFontBold, 40 ) pauseText.isVisible = false \<-- remove this to have the button there all the time local function gamePause( event ) if event.phase == "began" then gamePaused = not gamePaused if gamePaused then physics.pause() timer.pause( gameLoopTimer) pauseText:setText("Paused") else physics.start() timer.resume( gameLoopTimer) pauseText:setText("Pause") end pauseText.isVisible = gamePaused \<-- remove this to have the button there all the time end end