admob v2 attempt to call field 'init' (a nil value)

i’m trying to put a banner ad on the menu scene. i’m getting this error.

Runtime error

c:\users\me\documents\corona projects\game1\menu.lua:51: attempt to call field ‘init’ (a nil value)

stack traceback:

[C]: in function ‘error’

?: in function ‘gotoScene’

c:\users\me\documents\corona projects\game1\main.lua:15: in main chunk

main.lua is just

display.setStatusBar( display.HiddenStatusBar )

local composer = require “composer”

composer.gotoScene( “menu” )

the ads script in menu.lua is

local ads = require( “ads” )

local appID = “ca-app-pub-nnnnnnnnnnn/nnnnnnnnn”  <<in the app i used my real code here

local bannerAppID = “ca-app-pub-nnnnnnnnnnn/nnnnnnnnn” <<same code here

local adProvider = “admob”

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

        print( “Error, no ad received”, msg )

    else

        print( “Ah ha! Got one!” )

    end

end

ads.init( adProvider, appID, adListener )

ads.show( “banner”, { x=0, y=0, appId=bannerAppID } )

i added in build.settings

plugins = { [“plugin.google.play.services”] = { publisherId = “com.coronalabs” }, },

can anyone point me in the right direction?

What is line 51 of menu.lua?

can you post the whole build.settings?

this is the build.settings 

settings =

{

plugins =

    {

        [“plugin.google.play.services”] =

        {

            publisherId = “com.coronalabs”

        },

    }, 

orientation =

{

– Supported values for orientation:

– portrait, portraitUpsideDown, landscapeLeft, landscapeRight

default = “landscapeRight”,

supported = { “landscapeRight”,“landscapeLeft” }

},

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-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”,

},

–[[

– iOS app URL schemes:

CFBundleURLTypes =

{

{

CFBundleURLSchemes =

{

“fbXXXXXXXXX”,  – replace XXXXXXXXX with your Facebook appId

}

}

}

–]]

}

},

– Android Section

android =

{

usesPermissions =

{

“android.permission.INTERNET”,

“android.permission.ACCESS_NETWORK_STATE”,

},

},

}

and this is line 51 of menu.lua

ads.init( adProvider, appID, adListener )

Are there any additional error messages in your command windows?

no. 

i just did a test with the corona physics based game template and the script isn’t erroring so it must be something else in my scripts. I can’t imagine what.

i also tried copying the menu.lua from the template folder and using that instead of my original menu.lua and it’s giving the same error. so the error isn’t from the ad script, it’s something else in my game.        ???bah.   so confused right now.          i’ll just have to rewrite everything line by line or something.

with the new menu.lua template the console reads

Runtime error

c:\users\me\documents\corona projects\game1\menu.lua:40: attempt to call field ‘init’ (a nil value)

stack traceback:

[C]: in function ‘error’

?: in function ‘gotoScene’

c:\users\me\documents\corona projects\game1\main.lua:13: in main chunk

I’d start by making sure your build.settings is error free.  It’s hard to tell from the way you posted the build.settings above since it lost its indentions.  I didn’t spot any obvious errors.   But try it with a different build.settings and see where you go from there.

Rob

omg, i just realized what was going on. it’s so obvious i feel a bit stupid.

I made a scene to play interstitial ads between levels and guess what i named it…   you already know…  

ads

thank you so much for the quick responses Rob. whatever they pay you it isn’t enough.

What is line 51 of menu.lua?

can you post the whole build.settings?

this is the build.settings 

settings =

{

plugins =

    {

        [“plugin.google.play.services”] =

        {

            publisherId = “com.coronalabs”

        },

    }, 

orientation =

{

– Supported values for orientation:

– portrait, portraitUpsideDown, landscapeLeft, landscapeRight

default = “landscapeRight”,

supported = { “landscapeRight”,“landscapeLeft” }

},

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-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”,

},

–[[

– iOS app URL schemes:

CFBundleURLTypes =

{

{

CFBundleURLSchemes =

{

“fbXXXXXXXXX”,  – replace XXXXXXXXX with your Facebook appId

}

}

}

–]]

}

},

– Android Section

android =

{

usesPermissions =

{

“android.permission.INTERNET”,

“android.permission.ACCESS_NETWORK_STATE”,

},

},

}

and this is line 51 of menu.lua

ads.init( adProvider, appID, adListener )

Are there any additional error messages in your command windows?

no. 

i just did a test with the corona physics based game template and the script isn’t erroring so it must be something else in my scripts. I can’t imagine what.

i also tried copying the menu.lua from the template folder and using that instead of my original menu.lua and it’s giving the same error. so the error isn’t from the ad script, it’s something else in my game.        ???bah.   so confused right now.          i’ll just have to rewrite everything line by line or something.

with the new menu.lua template the console reads

Runtime error

c:\users\me\documents\corona projects\game1\menu.lua:40: attempt to call field ‘init’ (a nil value)

stack traceback:

[C]: in function ‘error’

?: in function ‘gotoScene’

c:\users\me\documents\corona projects\game1\main.lua:13: in main chunk

I’d start by making sure your build.settings is error free.  It’s hard to tell from the way you posted the build.settings above since it lost its indentions.  I didn’t spot any obvious errors.   But try it with a different build.settings and see where you go from there.

Rob

omg, i just realized what was going on. it’s so obvious i feel a bit stupid.

I made a scene to play interstitial ads between levels and guess what i named it…   you already know…  

ads

thank you so much for the quick responses Rob. whatever they pay you it isn’t enough.