If you are using my extension, the code should be a bit different, please see the docs.
https://docs.spiralcodestudio.com/extension/admob/init/#example
Hi! Sorry for the delay. I tried the example on github of your extension and it gave me that error on the remote launch of defold. I will try to export the example as apk and send it to my phone.
Remote launch is not compatible with native extensions. Build an APK and install it.
Ok I will send one to my phone.
Remote launch is available with native extensions.
But you need to install your custom executable first.
Hello again! I tested the test app on my phone and the test ad worked. Now I am trying to implement it into my game but I am having some trouble. In my init function I have this code :
admob.init{
app_id = 'ca-app-pub-685162264159115~9352519994',
test = true, -- ALWAYS use test ads, only disable when submitting to the stores.
listener = listener
}
Here is the code that makes the banner show up just in the script (not in init, update or anything)
local function listener(event)
if event.phase == 'init' then
admob.load{
type = 'banner',
id = 'ca-app-pub-561651641115/5277419906',
position = 'bottom',
size = 'smart',
position = 'bottom'
}
end
end
When I launch the app, it does not show up. What else do I need to put in?
If you separated those two pieces of code apart, it won’t work since the listener
variable is not visible to the admob.init()
function.
You can move this part
admob.load{
type = 'banner',
id = 'ca-app-pub-561651641115/5277419906',
position = 'bottom',
size = 'smart',
position = 'bottom'
}
to another script, but you have to make sure, that you have called admob.init()
before invoking admob.load()
and that init process was successful (init
phase of the event).
I moved the function code above the init code in the init function. There is still no ad. I looked at the example and there was no init. All I need is a simple banner ad.
Share all of your code. Everyone is guessing based on the little you’ve shared.
local function listener(event)
if event.phase == 'init' then -- Admob has been initialized, now it's safe to load a banner.
admob.load{
type = 'banner',
id = 'ca-app-pub-5899342264159115/5277419906',
position = 'bottom',
size = 'smart',
position = 'bottom'
}
end
end
admob.init{
app_id = 'ca-app-pub-5899342264159115~9352519994',
test = true, -- ALWAYS use test ads, only disable when submitting to the stores.
listener = listener
}
function init(self)
collectionfactory.create("#collectionfactory")
--admob.init('ca-app-pub-5899342264159115~9352519994', true)
end
function final(self)
sound.stop()
end
Here is my code that is in main.scipt. Here is my collection structure.
Here is my file structure.
Here is my game.project :
You should call admob.init() from within the init() lifecycle function.
What if you add a print() to the top of your listener function? Does it get called?
I tried but I can’t get a print when I bundle for android. I will try to make something happen when the listener gets called.
YES! The listener gets called. I made the listener toggle physics debug and it toggles after about 3 seconds.
Could it be that it has to do with Z order?
Could be, the default render script only renders things between -1 and 1.
Remember that the position is inherited, if a parent got 0.5 and the child got 0.7 the actual position is 1.2
To get the prints, launch adb logcat
.
Here’s a nifty deploy, launch and log script that I use in my daily work, in situations like this.
Ok! Thank you for the script. I will use it. Looked at Z axis ordering and found that the main.script was attached to the player game object which renders correctly so there is no problem there. Would attaching the main.scipt to a separate game object with a Z of 1 work? We know the issue is in the load function. Maybe position smart is overriding the Z.
I have re-downloaded sergey.lerg’s example and tried to export it for android and got an error. I then tried to use https://github.com/defold/extension-admob by mathiaswking. The example in for that project was working. I tried to scrape the example code to the bare bones to implement and read the docs. However, when I try to implement it, I don’t see the ads show up. Here is the code I used inside of a gui_scipt.
admob.load_banner(‘ca-app-pub-5899342264159115/5277419906’, { width = 320, height = 50 }, callback )
And then I added the following code in a button’s function. I also tried putting it in the callback. Both of which did not work.
admob.show_banner()
Just in case you were wondering, here is the error I get when I try sergey.lerg’s code in the example.
Sorry it was not letting my copy the error.
Not sure why the ad doesn’t show.
Do you get any error messages along the way?
For the “adUnitId” / “adSize”, there is this workaround: Admob extension failed building (DEF-3657)SOLVED
Sorry for the late response but just as a final note, I got it working. I used sergey.lerg’s code. I used that workaround and it all worked. If anyone in the future comes and needs help I can. For me it was a temp file issue and it now all works.