Error in ad placement!

I am trying to put ads in my game and it seems something went wrong. I have attached a screen shot of it.

It says attempt to call a nil value and more.I have studied updated star explorer project and added the code as it says in the main.lua file. I am not wanting to build game for ios and don’t want to put ads  for it.The code in build file and then main.lua is as followed. 

settings = { orientation = { -- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight default = "portrait", supported = { "portrait", }, }, plugins = { ["plugin.coronaAds"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, android=true } }, ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, ["shared.android.support.v4"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, } excludeFiles = { -- Include only the necessary icon files on each platform iphone = { "Icon-\*dpi.png", }, android = { "Icon.png", "Icon-Small-\*.png", "Icon\*@2x.png", }, }, -- -- iOS Section -- iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend CFBundleIconFiles = { "Icon.png", "Icon@2x.png", "Icon-167.png", "Icon-60.png", "Icon-60@2x.png", "Icon-60@3x.png", "Icon-72.png", "Icon-72@2x.png", "Icon-76.png", "Icon-76@2x.png", "Icon-Small.png", "Icon-Small@2x.png", "Icon-Small@3x.png", "Icon-Small-40.png", "Icon-Small-40@2x.png", "Icon-Small-50.png", "Icon-Small-50@2x.png", }, }, }, -- -- Android Section -- android = { usesPermissions = { "android.permission.INTERNET", }, }, }

composer.gotoScene( "menu" ) local coronaAds = require( "plugin.coronaAds" ) local apiKey = "myapikeyno" -- Corona Ads listener function local function adListener( event ) -- Successful initialization of Corona Ads if ( event.phase == "init" ) then composer.setVariable( "coronaAdsInitialized", true ) end end coronaAds.init( apiKey, adListener )

Which line is line 15? I count 11 lines. Also corona ads don’t work in simulator.

Does that explain the plugin.coronaads warning I get in the simulator?

Many of the plugins only work on device and in the simulator you get a warning like:

WARNING: The PluginName plugin is only supported on Android & iOS devices. Please build for device

This is because the plugin is using an SDK and that vendor only made the plugin for mobile device operating systems. Windows and macOS are not mobile device operating systems and there is no SDK available. Instead of getting errors preventing your app from working we download “stub” plugins that have all the API calls, but they emit the message. This lets  you continue to use the simulator for other things but when you need to test those specific features you have to build for the device.

Here is it! Please help!

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- hide the status bar display.setStatusBar( display.HiddenStatusBar ) -- include the Corona "composer" module local composer = require "composer" -- load menu screen composer.gotoScene( "menu" ) local coronaAds = require( "plugin.coronaAds" ) local apiKey = "e2f23154-3095-43cd-95e7-2c036c21c06f" -- Corona Ads listener function local function adListener( event ) -- Successful initialization of Corona Ads if ( event.phase == "init" ) then composer.setVariable( "coronaAdsInitialized", true ) end end coronaAds.init( apiKey, adListener )

Can you humor me and rewrite your code to be:

local coronaAds = require( "plugin.coronaAds" ) display.setStatusBar( display.HiddenStatusBar ) local apiKey = "e2f23154-3095-43cd-95e7-2c036c21c06f" -- Corona Ads listener function local function adListener( event ) -- Successful initialization of Corona Ads if ( event.phase == "init" ) then composer.setVariable( "coronaAdsInitialized", true ) end end coronaAds.init( apiKey, adListener ) -- include the Corona "composer" module local composer = require "composer" -- load menu screen composer.gotoScene( "menu" )

Also what is your build.settings file?

Are you getting any more messages in your console log (the window that opens behind your simulator)?

What version of Corona are you using?

Hi, but the code you provided is still not working and system is getting the same error. I am using v2016.2906 version of corona simulator.Also I have attached screen shot of console log and it is displaying same error as simulator. The code of build.settings file is…

-- -- For more information on build.settings see the Corona SDK Build Guide at: -- https://docs.coronalabs.com/guide/distribution/buildSettings -- settings = { orientation = { -- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight default = "portrait", supported = { "portrait" }, }, plugins = { ["plugin.coronaAds"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, ["shared.android.support.v4"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, } excludeFiles = { -- Include only the necessary icon files on each platform iphone = { "Icon-\*dpi.png", }, android = { "Icon.png", "Icon-Small-\*.png", "Icon\*@2x.png", }, }, -- -- iOS Section -- iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend CFBundleIconFiles = { "Icon.png", "Icon@2x.png", "Icon-167.png", "Icon-60.png", "Icon-60@2x.png", "Icon-60@3x.png", "Icon-72.png", "Icon-72@2x.png", "Icon-76.png", "Icon-76@2x.png", "Icon-Small.png", "Icon-Small@2x.png", "Icon-Small@3x.png", "Icon-Small-40.png", "Icon-Small-40@2x.png", "Icon-Small-50.png", "Icon-Small-50@2x.png", }, }, }, -- -- Android Section -- android = { usesPermissions = { "android.permission.INTERNET", }, }, }
settings = { orientation = { default ="portrait", supported = {"portrait"}, }, plugins = { ["plugin.coronaAds"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, android=true } }, ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, ["shared.android.support.v4"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, }, iphone = { plist = { NSAppTransportSecurity = { NSAllowsArbitraryLoads=true }, NSLocationAlwaysUsageDescription = { "" }, NSLocationWhenInUseUsageDescription = { "" }, }, }, }

local composer = require( "composer" ) -- Hide status bar display.setStatusBar( display.HiddenStatusBar ) -- Seed the random number generator math.randomseed( os.time() ) -- Include Corona Ads local coronaAds = require( "plugin.coronaAds" ) local apiKey = "663cf134-779d-4427-bde8-9e413ab67747" -- Corona Ads listener function local function adListener( event ) -- Successful initialization of Corona Ads if ( event.phase == "init" ) then composer.setVariable( "coronaAdsInitialized", true ) end end -- Initialize Corona Ads coronaAds.init( apiKey, adListener ) -- Reserve channel 1 for background music audio.reserveChannels( 1 ) -- Reduce the overall volume of the channel audio.setVolume( 0.5, { channel=1 } ) -- Go to the menu screen composer.gotoScene( "menu" )

My build.settings(top) and my main.lua(bottom). This worked perfectly fine for me.

Where have you tried using the ad? Corona’s errors like all other errors are never 100% accurate. Post the code where you tried using the ad.

 } --\<------- you need a comma here excludeFiles =

You need to add a comma after the curly brace I indicated above. 

Rob

Here is the code that is placed in the end scene of game. 

local composer = require( "composer" ) local scene = composer.newScene() local widget = require "widget" local playButton -------------------------------------------- local coronaAds = require( "plugin.coronaAds" ) local interstitialPlacement = "end" local function showAd( event ) -- Show an ad if ( composer.getVariable( "coronaAdsInitialized" ) == true ) then coronaAds.show( interstitialPlacement, true ) end end local function destroyScene() composer.gotoScene( "game", { time=800, effect="crossFade" } ) composer.removeScene("end") end function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen local background = display.newImageRect( scene.view, "relaunch.png",display.actualContentWidth, display.actualContentHeight ) background.x = display.contentCenterX background.y = display.contentCenterY local laserSound = audio.loadSound( "end.mp3" ) local laserChannel = audio.play( laserSound ) local function playButton () playButton = display.newText( scene.view, "Play", display.contentCenterX, display.contentCenterY+180, native.systemFont, 44 ) playButton:setFillColor( 0.8, 2.2, 1.3 ) playButton:addEventListener( "tap", function() composer.gotoScene( "game", { time=800, effect="crossFade" } ) end ) playButton:addEventListener( "tap", function () destroyScene() end ) end local myclosure = function () return playButton () end timer.performWithDelay( 7000, myclosure, 1) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then showAd() local myclosure1 = function () return showAd() end timer.performWithDelay( 7000, myclosure1, 1) elseif phase == "did" then end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) elseif phase == "did" then -- Called when the scene is now off screen end end function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's "view" (sceneGroup) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. if playButton then display.remove( playButton ) playButton:removeSelf() -- widgets must be manually removed playButton = nil end end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene

Which line is line 15? I count 11 lines. Also corona ads don’t work in simulator.

Does that explain the plugin.coronaads warning I get in the simulator?

Many of the plugins only work on device and in the simulator you get a warning like:

WARNING: The PluginName plugin is only supported on Android & iOS devices. Please build for device

This is because the plugin is using an SDK and that vendor only made the plugin for mobile device operating systems. Windows and macOS are not mobile device operating systems and there is no SDK available. Instead of getting errors preventing your app from working we download “stub” plugins that have all the API calls, but they emit the message. This lets  you continue to use the simulator for other things but when you need to test those specific features you have to build for the device.

Here is it! Please help!

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- hide the status bar display.setStatusBar( display.HiddenStatusBar ) -- include the Corona "composer" module local composer = require "composer" -- load menu screen composer.gotoScene( "menu" ) local coronaAds = require( "plugin.coronaAds" ) local apiKey = "e2f23154-3095-43cd-95e7-2c036c21c06f" -- Corona Ads listener function local function adListener( event ) -- Successful initialization of Corona Ads if ( event.phase == "init" ) then composer.setVariable( "coronaAdsInitialized", true ) end end coronaAds.init( apiKey, adListener )

Can you humor me and rewrite your code to be:

local coronaAds = require( "plugin.coronaAds" ) display.setStatusBar( display.HiddenStatusBar ) local apiKey = "e2f23154-3095-43cd-95e7-2c036c21c06f" -- Corona Ads listener function local function adListener( event ) -- Successful initialization of Corona Ads if ( event.phase == "init" ) then composer.setVariable( "coronaAdsInitialized", true ) end end coronaAds.init( apiKey, adListener ) -- include the Corona "composer" module local composer = require "composer" -- load menu screen composer.gotoScene( "menu" )

Also what is your build.settings file?

Are you getting any more messages in your console log (the window that opens behind your simulator)?

What version of Corona are you using?

Hi, but the code you provided is still not working and system is getting the same error. I am using v2016.2906 version of corona simulator.Also I have attached screen shot of console log and it is displaying same error as simulator. The code of build.settings file is…

-- -- For more information on build.settings see the Corona SDK Build Guide at: -- https://docs.coronalabs.com/guide/distribution/buildSettings -- settings = { orientation = { -- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight default = "portrait", supported = { "portrait" }, }, plugins = { ["plugin.coronaAds"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, ["shared.android.support.v4"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, } excludeFiles = { -- Include only the necessary icon files on each platform iphone = { "Icon-\*dpi.png", }, android = { "Icon.png", "Icon-Small-\*.png", "Icon\*@2x.png", }, }, -- -- iOS Section -- iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend CFBundleIconFiles = { "Icon.png", "Icon@2x.png", "Icon-167.png", "Icon-60.png", "Icon-60@2x.png", "Icon-60@3x.png", "Icon-72.png", "Icon-72@2x.png", "Icon-76.png", "Icon-76@2x.png", "Icon-Small.png", "Icon-Small@2x.png", "Icon-Small@3x.png", "Icon-Small-40.png", "Icon-Small-40@2x.png", "Icon-Small-50.png", "Icon-Small-50@2x.png", }, }, }, -- -- Android Section -- android = { usesPermissions = { "android.permission.INTERNET", }, }, }
settings = { orientation = { default ="portrait", supported = {"portrait"}, }, plugins = { ["plugin.coronaAds"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, android=true } }, ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, ["shared.android.support.v4"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, }, iphone = { plist = { NSAppTransportSecurity = { NSAllowsArbitraryLoads=true }, NSLocationAlwaysUsageDescription = { "" }, NSLocationWhenInUseUsageDescription = { "" }, }, }, }

local composer = require( "composer" ) -- Hide status bar display.setStatusBar( display.HiddenStatusBar ) -- Seed the random number generator math.randomseed( os.time() ) -- Include Corona Ads local coronaAds = require( "plugin.coronaAds" ) local apiKey = "663cf134-779d-4427-bde8-9e413ab67747" -- Corona Ads listener function local function adListener( event ) -- Successful initialization of Corona Ads if ( event.phase == "init" ) then composer.setVariable( "coronaAdsInitialized", true ) end end -- Initialize Corona Ads coronaAds.init( apiKey, adListener ) -- Reserve channel 1 for background music audio.reserveChannels( 1 ) -- Reduce the overall volume of the channel audio.setVolume( 0.5, { channel=1 } ) -- Go to the menu screen composer.gotoScene( "menu" )

My build.settings(top) and my main.lua(bottom). This worked perfectly fine for me.