This is all in my scorescreen.lua scene, after a round of play. Most of the surrounding logic is to control whether or not the ads should be displayed (based on IAP or other app variation, and to only show ads every third round)
local coronaAds if (system.getInfo("targetAppStore") ~= "amazon" ) then -- comment out for MBN+ coronaAds = require( "plugin.coronaAds" ) print ("coronaAds has been required") end
The ‘listener’ - I have not seen any debug statement (alerts or print) show up from this function
-- Event listener function local function coronaListener( event ) local alert local interstitialPlacement if (system.getInfo("targetAppStore") == "google" ) then interstitialPlacement = "interstitial-1-MBN" end alert = native.showAlert( "Ad - in Listener", "event.name = "..event.name, { "OK", "Cancel" } ) if DATA.screenshowncount ~= 0 then -- add condition for 'init'?? if ( event.phase == "found" ) then --alert = native.showAlert( "Ad - found", "should show ad next ", { "OK", "Cancel" } ) coronaAds.show( interstitialPlacement, true ) elseif ( event.phase == "failed" ) then --alert = native.showAlert( "Ad - failed", "should repeat loop next ", { "OK", "Cancel" } ) timers.t10 = timer.performWithDelay(500,showButtons) DATA.screenshowncount = 3 elseif ( event.phase == "closed" ) then --alert = native.showAlert( "Ad - closed", "should restart count ", { "OK", "Cancel" } ) timers.t10 = timer.performWithDelay(200,showButtons) DATA.screenshowncount = 1 else --alert = native.showAlert( "Ad - no phase", "condition not accounted for, event.phase = "..event.phase, { "OK", "Cancel" } ) timers.t10 = timer.performWithDelay(500,showButtons) end else --alert = native.showAlert( "Ad - count 0", "condition not tested, event.phase = "..event.phase, { "OK", "Cancel" } ) DATA.screenshowncount = 1 timers.t10 = timer.performWithDelay(500,showButtons) end alert = nil end
This showCoronaAds function is run, and it will stop in the condition DATA.screenshowncount == 0 (this value is set earlier) and the first attempt to init never occurs, the listener never executes. (I have tried other ways to get the init to occur, but have not been successful)
local showCoronaAds = function () print("showCoronaAds called") local alert if DATA.adPurchased == false then if DATA.displayAds == true then print("in showCoronaAds function") -- count every third cycle if DATA.screenshowncount \>= 3 then print("call to corona.init") alert = native.showAlert( "Ad - call to init to show ad", "DATA.screenshowncount = "..DATA.screenshowncount, { "OK", "Cancel" } ) coronaAds.init( "MY API ID goes here", coronaListener ) elseif DATA.screenshowncount == 0 then print("call to corona.init in count = 0") --alert = native.showAlert( "Ad - first call to init", "DATA.screenshowncount = "..DATA.screenshowncount, { "OK", "Cancel" } ) coronaAds.init( "MY API ID goes here", coronaListener ) else DATA.screenshowncount = DATA.screenshowncount + 1 alert = native.showAlert( "Ad - no call to init", "DATA.screenshowncount = "..DATA.screenshowncount, { "OK", "Cancel" } ) print("screenshowncount = "..DATA.screenshowncount) timers.t10 = timer.performWithDelay(500,showButtons) end
The function call that gets the ball rolling (there are a couple instances of this in different conditions). This is in the scene:show functions where phase == “will”
timers.t9 = timer.performWithDelay(200,showCoronaAds)