Ad is showing only one time?

So, I implemented monetization through Appodeal, but i’m having a strange issue: the ad is showing up only when I launch the game for the first time! I know that code outside the scene events is going to be run only one time, and that’s why I call the function to show the ad in the scene:show and hide it in the scene:hide. 

But when I move to another scene and then go back to my “menu” scene, which is where I want the ad to show up, it doesn’t. Any ideas ? 

Thanks.

I would suggest you read this blog post and the associated tutorial.

https://coronalabs.com/blog/2018/10/02/monetization-best-practices-and-a-new-ad-tutorial/

Rob

I followed it already, look I’ll paste some of my code. 

function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) local menumusic menumusic = audio.loadStream("audio/menumusic.mp3") audio.play(menumusic, {loops=-1}) --------SHOW AD---------- local appodeal = require( "plugin.appodeal" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Show a banner ad appodeal.show( "banner", { yAlign="top" } ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end -- Initialize the Appodeal plugin appodeal.init( adListener, { appKey="462df4d656428178a60f7cf753f1aa05fc38a60f54b55c95" } ) ------------------------- elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen local menumusic menumusic = audio.loadStream("audio/menumusic.mp3") audio.play(menumusic, {loops=-1}) --------SHOW AD---------- local appodeal = require( "plugin.appodeal" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Show a banner ad appodeal.show( "banner", { yAlign="top" } ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end -- Initialize the Appodeal plugin appodeal.init( adListener, { appKey="462df4d656428178a60f7cf753f1aa05fc38a60f54b55c95" } ) ------------------------- end end

I actually have it, as you can see, both on will and on did. The fact is, if I delete the “will”, the ad doesn’t pop up at all. 

If I leave it on will, or even both of them, the ad will show up, go away because I hide it in the scene:hide(event) but won’t reappear after I come back to the menu scene. 

EDIT: 

I tried removing totally the “will” phase and leave just the “did” phase and it works, but the ad still doesn’t pop when I go back to the menu. 

EDIT 2: 

Apparently I just can’t have it in the scene:show(event). 

What I said applies only if I leave the code in the scene:create for some reasons. 

EDIT 3: 

Also, why do you give me a guide where the code is for admob?

You apparently missed a very key point in the tutorial:

“Initialization should only happen once. This is best done in main.lua, but for more advanced setups, you could create a module to hold your advertising code and require that module in main.lua, but for most, you will do all of this in main.lua.”

You should not be initializing the plugin in a scene. The only thing a scene should do is show an ad, hide if necessary, and load the next ad. 

Rob

I removed the other initializations but the problems persists: I can clearly see from the console that if I paste the command 

appodeal.show( "banner", { yAlign="top" } ) 

in the scene:create(event) the function will be called. However if I put it in the scene:show(event) it won’t be called in the console. 

I managed to get it called buy the console, using just the command appeal.show() but still, even if in console everything seems to work, once I build it for the device the ad won’t pop up. 

I’m not sure what you mean by “I managed to get it called by the console”. Can you clarify?

Can you post your current code?

Rob

I solved it. To be honest I am not a hundred percent sure how I did it, but I am pretty sure I was doing something wrong in the init of the Appodeal plugin in my main and it wasn’t able to call properly the show functions, even though everything appeared in the console. 
I also made some changes to the scene:show() did part and that worked too. 

Thank you for the help anyways. 

You can mark as solved, I will now post my code so if someone has troubles they could refer to this: 

ALSO I HIGHLY SUGGEST TO REMOVE YANDEX AS IT STILL CAUSE iOS REJECTION

My settings 

 plugins = { -- Base ['plugin.appodeal.base'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.AmazonAds'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.GoogleAdMob'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.TwitterMoPub'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.StartApp'] = { publisherId = 'com.coronalabs' }, -- Banner ['plugin.appodeal.AppLovin'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.FacebookAudience'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.Flurry'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.InMobi'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.MyTarget'] = { publisherId = 'com.coronalabs' }, },

My main

local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.isError ) end end -- Initialize the Appodeal plugin appodeal.init( adListener, { appKey="462df4d656428178a60f7cf753f1aa05fc38a60f54b55c95" } )

My scene 

elseif ( phase == "did" ) then --[...other code of mine was here...] appodeal.show( "banner", { yAlign="top" } ) end

And then I just called Appodeal.hide in the hide scene. 

I would suggest you read this blog post and the associated tutorial.

https://coronalabs.com/blog/2018/10/02/monetization-best-practices-and-a-new-ad-tutorial/

Rob

I followed it already, look I’ll paste some of my code. 

function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) local menumusic menumusic = audio.loadStream("audio/menumusic.mp3") audio.play(menumusic, {loops=-1}) --------SHOW AD---------- local appodeal = require( "plugin.appodeal" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Show a banner ad appodeal.show( "banner", { yAlign="top" } ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end -- Initialize the Appodeal plugin appodeal.init( adListener, { appKey="462df4d656428178a60f7cf753f1aa05fc38a60f54b55c95" } ) ------------------------- elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen local menumusic menumusic = audio.loadStream("audio/menumusic.mp3") audio.play(menumusic, {loops=-1}) --------SHOW AD---------- local appodeal = require( "plugin.appodeal" ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Show a banner ad appodeal.show( "banner", { yAlign="top" } ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end -- Initialize the Appodeal plugin appodeal.init( adListener, { appKey="462df4d656428178a60f7cf753f1aa05fc38a60f54b55c95" } ) ------------------------- end end

I actually have it, as you can see, both on will and on did. The fact is, if I delete the “will”, the ad doesn’t pop up at all. 

If I leave it on will, or even both of them, the ad will show up, go away because I hide it in the scene:hide(event) but won’t reappear after I come back to the menu scene. 

EDIT: 

I tried removing totally the “will” phase and leave just the “did” phase and it works, but the ad still doesn’t pop when I go back to the menu. 

EDIT 2: 

Apparently I just can’t have it in the scene:show(event). 

What I said applies only if I leave the code in the scene:create for some reasons. 

EDIT 3: 

Also, why do you give me a guide where the code is for admob?

You apparently missed a very key point in the tutorial:

“Initialization should only happen once. This is best done in main.lua, but for more advanced setups, you could create a module to hold your advertising code and require that module in main.lua, but for most, you will do all of this in main.lua.”

You should not be initializing the plugin in a scene. The only thing a scene should do is show an ad, hide if necessary, and load the next ad. 

Rob

I removed the other initializations but the problems persists: I can clearly see from the console that if I paste the command 

appodeal.show( "banner", { yAlign="top" } ) 

in the scene:create(event) the function will be called. However if I put it in the scene:show(event) it won’t be called in the console. 

I managed to get it called buy the console, using just the command appeal.show() but still, even if in console everything seems to work, once I build it for the device the ad won’t pop up. 

I’m not sure what you mean by “I managed to get it called by the console”. Can you clarify?

Can you post your current code?

Rob

I solved it. To be honest I am not a hundred percent sure how I did it, but I am pretty sure I was doing something wrong in the init of the Appodeal plugin in my main and it wasn’t able to call properly the show functions, even though everything appeared in the console. 
I also made some changes to the scene:show() did part and that worked too. 

Thank you for the help anyways. 

You can mark as solved, I will now post my code so if someone has troubles they could refer to this: 

ALSO I HIGHLY SUGGEST TO REMOVE YANDEX AS IT STILL CAUSE iOS REJECTION

My settings 

 plugins = { -- Base ['plugin.appodeal.base'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.AmazonAds'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.GoogleAdMob'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.TwitterMoPub'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.StartApp'] = { publisherId = 'com.coronalabs' }, -- Banner ['plugin.appodeal.AppLovin'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.FacebookAudience'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.Flurry'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.InMobi'] = { publisherId = 'com.coronalabs' }, ['plugin.appodeal.MyTarget'] = { publisherId = 'com.coronalabs' }, },

My main

local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization print( event.isError ) end end -- Initialize the Appodeal plugin appodeal.init( adListener, { appKey="462df4d656428178a60f7cf753f1aa05fc38a60f54b55c95" } )

My scene 

elseif ( phase == "did" ) then --[...other code of mine was here...] appodeal.show( "banner", { yAlign="top" } ) end

And then I just called Appodeal.hide in the hide scene.