ads.hide()

I am put a banner ad in my restart scene but when i click on the screen to restart the game the ad is in the game and i don’t want it there, so I put in ads.hide() in the game scene but it is not working . 

game.lua 

-- requires local ads = require "ads" local physics = require "physics" physics.start() local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- background ads.hide() function scene:createScene(event) local screenGroup = self.view local background = display.newImageRect("bg.png",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) ceiling = display.newImage("invisibleTile.png") ceiling.x = 0 ceiling.y = -33 physics.addBody(ceiling, "static", {density=.1, bounce=0.2, friction=.2}) screenGroup:insert(ceiling) theFloor = display.newImage("invisibleTile.png") theFloor.x = 0 theFloor.y = 365 physics.addBody(theFloor, "static", {density=.1, bounce=0.2, friction=.2}) screenGroup:insert(theFloor) city1 = display.newImage("city1.png") city1.x = 240 city1.y = 210 city1.speed = 2 screenGroup:insert(city1) city2 = display.newImage("city1.png") city2.x = 240 city2.y = 270 city2.speed = 2 screenGroup:insert(city2) city3 = display.newImage("city2.png") city3.x = 240 city3.y = 270 city3.speed = 3 screenGroup:insert(city3) city4 = display.newImage("city2.png") city4.x = 240 city4.y = 270 city4.speed = 3 screenGroup:insert(city4) jet = display.newImage("redJet.png") jet.x = 100 jet.y = 100 physics.addBody(jet, "dynamic", {density=.1, bounce=0.2, friction=.2, radius=12}) screenGroup:insert(jet) mine1 = display.newImage("mine.png") mine1.x = 500 mine1.y = 100 mine1.speed = math.random(4,8) mine1.initY = mine1.y mine1.amp = math.random(20, 100) mine1.angle = math.random(1, 360) physics.addBody(mine1, "static", {density=.1, bounce=0.2, friction=.2, radius=12}) screenGroup:insert(mine1) mine2 = display.newImage("mine.png") mine2.x = 500 mine2.y = 100 mine2.speed = math.random(4,8) mine2.initY = mine2.y mine2.amp = math.random(20, 100) mine2.angle = math.random(1, 360) physics.addBody(mine2, "static", {density=.1, bounce=0.2, friction=.2, radius=12}) screenGroup:insert(mine2) mine3 = display.newImage("mine.png") mine3.x = 500 mine3.y = 100 mine3.speed = math.random(4,8) mine3.initY = mine3.y mine3.amp = math.random(20, 100) mine3.angle = math.random(1, 360) physics.addBody(mine3, "static", {density=.1, bounce=0.2, friction=.2, radius=12}) screenGroup:insert(mine3) mine4 = display.newImage("mine.png") mine4.x = 500 mine4.y = 100 mine4.speed = math.random(2,10) mine4.initY = mine4.y mine4.amp = math.random(20, 100) mine4.angle = math.random(1, 360) physics.addBody(mine4, "static", {density=.1, bounce=0.2, friction=.2, radius=12}) screenGroup:insert(mine4) end function scrollCity( self, event ) if self.x \< -200 then self.x = 200 else self.x = self.x - self.speed end end function moveMines( self, event ) if self.x \< -50 then self.x = 500 self.y = math.random(90, 220) self.speed = math.random(4,8) self.initY = mine1.y self.amp = math.random(20, 100) self.angle = math.random(1, 360) else self.x = self.x - self.speed self.angle = self.angle + .1 self.y = self.amp\*math.sin(self.angle)+self.initY end end -- jet function activateJets( self, event ) self:applyForce(0, -4.7, self.x, self.y) end function touchScreen( event ) if event.phase == "began" then jet.enterFrame = activateJets Runtime: addEventListener("enterFrame", jet) end if event.phase == "ended" then Runtime: removeEventListener("enterFrame", jet) end end function onCollision( event ) if event.phase =="began" then storyboard.gotoScene("restart", "fade", 400) end end function scene:enterScene(event) city1.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city1) city2.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city2) city3.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city3) city4.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city4) mine1.enterFrame = moveMines Runtime:addEventListener("enterFrame", mine1) mine2.enterFrame = moveMines Runtime:addEventListener("enterFrame", mine2) mine3.enterFrame = moveMines Runtime:addEventListener("enterFrame", mine3) mine4.enterFrame = moveMines Runtime:addEventListener("enterFrame", mine4) Runtime:addEventListener("touch", touchScreen) Runtime:addEventListener("collision", onCollision) end function scene:exitScene(event) Runtime:removeEventListener("touch", touchScreen) Runtime:removeEventListener("enterFrame", city1) Runtime:removeEventListener("enterFrame", city2) Runtime:removeEventListener("enterFrame", city3) Runtime:removeEventListener("enterFrame", city4) Runtime:removeEventListener("enterFrame", mine1) Runtime:removeEventListener("enterFrame", mine2) Runtime:removeEventListener("enterFrame", mine3) Runtime:removeEventListener("collision", onCollision) end function scene:destroyScene(event) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene

This is a scope issue. Because you have put “ads.hide()” outside of any scene event function, it will only execute once when that scene module is first loaded into memory. That line will never be called again when you return to the scene later. You should probably put that line inside the function where the scene “enters”.

Brent

This is a scope issue. Because you have put “ads.hide()” outside of any scene event function, it will only execute once when that scene module is first loaded into memory. That line will never be called again when you return to the scene later. You should probably put that line inside the function where the scene “enters”.

Brent