Below is the code I have in my Build Setttings, main.lua and levelComplete.lua. level complete is where my game goes when a player either ends the level or completes the level. On that screen they can press one of three buttons: Replay Level, Play Next Level or End Game.
I had the code set up like below and for a while the ads appeared but I had a loop and ads kept showing every time I pressed a button. So I tried putting some code at the end of the phase of pressing the buttons but I couldn’t get the ads to show up. The screen locked up.
So, I went back and set it up like below to see the ads again and now nothing. No ads.
I’m not sure what I’m doing wrong and would appreciate any guidance.
Thanks,
Lori
BUILD SETTINGS
settings =
{
–ORIENTATION TABLE
orientation =
{
default = “portrait”,
supported = { “portrait”}
},
–PLUGINS TABLE
plugins =
{
-----------------------------------------------------------------------------
--CORONA
-----------------------------------------------------------------------------
[“CoronaProvider.gameNetwork.apple”] =
{
publisherId = “com.coronalabs”,
supportedPlatforms = { iphone=true, [“iphone-sim”]=true },
},
-----------------------------------------------------------------------------
--ADS MOB
-----------------------------------------------------------------------------
[“plugin.google.play.services”] = { publisherId = “com.coronalabs” },
},
android =
{
usesPermissions =
{
“android.permission.INTERNET”,
“android.permission.ACCESS_NETWORK_STATE”,
},
MAIN.LUA
–Assign Various Ad ID’s
local interstitialAppID = “ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXX” – for IOS interstitial–
if (system.getInfo(“platformName”) == “Android”) then
interstitialAppID = “ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXXXXXX” --for Android int
end
local adProvider = “admob”
local ads = require (“ads”) --Require the Ads Plugin
local testMode = true
local function adListener( event )
for k,v in pairs( event ) do
print("adListener ", k, v ) – so you see everything you get
end
end
local function adListener(event)
– The ‘event’ table includes:
– event.name: string value of “adsRequest”
– event.response: message from the ad provider about the status of this request
– event.phase: string value of “loaded”, “shown”, or “refresh”
– event.type: string value of “banner” or “interstitial”
– event.isError: boolean true or false
local msg = event.response
– Quick debug message regarding the response from the library
print( "Message from the ads library: ", msg )
if ( event.isError ) then
– attempt to fetch another ad
elseif ( event.phase == “loaded” ) then
– an ad was preloaded
elseif ( event.phase == “shown” ) then
– the ad was viewed and closed
end
end
if ( ads.isLoaded(“interstitial”) ) then
ads.show(“interstitial”)
end
appID = interstitialAppID
ads.init (adProvider, appID, adListener)
ads:setCurrentProvider(“admob”)
ads.load(“admob”, { appId = interstitialAppID, testMode = testMode } )
LEVEL COMPLETE SCREEN
local ads = require (“ads”) --Require the Ads Plugin
local testMode = true
------------------------------------------------------------------------
–SCENE SHOW
------------------------------------------------------------------------
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == “will” then
– Called when the scene is still off screen and is about to move on screen
elseif phase == “did” then
–AD MOB
ads.load(“interstitial”, { appId=interstitialAppID } )
ads.show(“interstitial”, { appId=interstitialAppID } )
------------------------------------------------------------------------
–SCENE HIDE
------------------------------------------------------------------------
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == “will” then
ads.hide( “interstitial” )
elseif phase == “did” then
– Called when the scene is now off screen
composer.removeScene(“levelComplete”)
end
end