Ads

@elbowroomapps I tried using this source many time but I just cant seem to get it right. Is there any way that you can show me what the finished code should look like?

I took the iAds example that comes with coronasdk and modified it to use admob instead of iAds. You can download the modified files here:

https://app.box.com/s/489657irqj2c7y9brobz

In the main.lua file, you will see the following line:

local appID = “ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX”

You should edit that line and insert the appID for your admob account. Then build the app and install it on an iOS or android device. The app will show buttons that let you show and hide the ads.

I dont want this @elbowroomapps. I already have an app, I just want to have interstitial ads pop up when you die in my app. How do I do that?

I want ads to show up when you die on my app, how do I do that?

@elbowroomgames I did what you said, and yes the interstitial ad shows up, but how do I make it show up on my own app after you die? what code to I type?

If you have correctly included the plugin and run ads.init, then you just need to call ads.show at the point in your code when you want to show the add. The line would look like this:

ads.show( “interstitial”, { x=adX, y=adY, testMode=true } )

@elbowroomgames It worked! But it only showed up once. How do I make it show up multiple times?

It also shows up about three seconds into the game everytime, whether you die or not. How to I make it show up multiple times and on a specific screen when I die? @elbowroomgames

That’s going to depend on your code. You have to put the call to ads.show() at the right spot in your code.Have you tried looking at the sample code? It only shows the ads when you press a button and not before.

Here is part of my c main.lua code

local ads = require( "ads" ) local appID = "ca-app-pub-xxx" 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: 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( "admob", "ca-app-pub-xxx", adListener ) ads.show("interstitial",{x=0, y=0, testMode= true})

My ads.show is at the end of it. Where do I put it to make it show up when you die? And show up more than once?

@elbowroomapps

In your code, how do you know when the character dies? What does your app do when the character dies?

You need to find the spot in your code that handles the character dying, then put the ads.show line there.

@elbowroomapps Should this be in the main.lua or the game.lua

Leave everything in main.lua except for the ads.show. You can just put the ads.show anywhere in game.lua. You have to find the place in the code where the character dies, and then put the ads.show there.

okay thanks! @elbowroomapps

Do I have to do two ads.init() comands if I am using both banner and interstitial ads? @elbowroomapps

I got it to work but there is a delay for the ad to show up after you die. How do I make it show up right when you die?

It’s great you got it working. The ads have to be downloaded over your internet connection, so you might notice the delay if you have a slow connection. I’m not aware of any way to speed it up. 

There have been several threads in these forums on using admob. I would suggest reading through those to see if other people have seen the same problem and what solutions they came up with.