Help with having chartBoost Interstitial show up as soon as it's loaded

Hello, I’m trying to get an interstitial ad to show up as soon as it’s ready to be shown but I am having some troubles. I know it can work, because previously I had it showing up if admob banner doesn’t work (just practicing with it). But now I’m giving it it’s own function separate from admob but I can’t for the life of me get it to show up. If anyone can help me with my code or even suggest an easier way then I’ll really appreciate it!

P.S. event.isError was something I pulled from my admob function that I’ll eventually take out because I know chartBoost doesn’t use it.

Thanks!

[lua]

local function chartBoostListener( event )

print (“chartBoostListener Called”)

if ( event.isError ) then

else

print (“Here!! *******”)   --*This is weirdly where terminal stops. Last line doesn’t show up, and no errors come up

print (“has cached interstitial?”…chartboost.hasCachedInterstitial())

if chartboost.hasCachedInterstitial() then

print(“Chartboost has cached ad”)

chartboost.show( “interstitial” )

print (“Here2!!! *******”)

else

print (“test mark”)

chartBoostListener()

print (“test mark 2”)

end 

end

   – for k, v in pairs( event ) do

     –   print( tostring(k)… “=”… tostring(v) )

    --end

end


—ads.init( adProvider, appID, adListenerFunction )

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

–ads.show( “interstitial”, { appId=interstitialAppID } )    – uncomment this when you get banner to work


local chartboost = require( “plugin.chartboost” )

print (“placeholder 1”)

chartboost.init {

        appID        = “54dff5ed43150f0f55d0000a”,        --I changed these b/c I’m assuming I shouldn’t share it?

        appSignature = “22d7ec10c4d220a1c4f46b6fe19b9a834c000000”, 

        listener     = chartBoostListener

        --change listener to     adListenerFunction

    }

–chartboost.startSession( “54dff5ed43150f0f55d4639a”, “22d7ec10c4d220a1c4f46b6fe19b9a834c0f3d8d” ) --(appID, appSignature)

–chartboost.show( “interstitial”, “Startup” )

chartboost.cache( “interstitial” )

print (“chartboost was told to be cached****”)

local function systemEvent( event )

    local phase = event.phase

print (“systemEventfunction*******”)

    if event.type == “applicationResume” then

        – Start a ChartBoost session after screen comes back from idle? and accurately allows chartboost to manage impressions/click rates

        print (“Start Chartboost session ******”)

        chartboost.startSession( “54dff5ed43150f0f55d4639a”, “22d7ec10c4d220a1c4f46b6fe19b9a834c0f3d8d” )

        --chartboostFunction()

    end

    

    return true

end

Runtime:addEventListener( “system”, systemEvent )

[/lua]

Terminal:

[lua]

> Class.forName: plugin.chartboost.LuaLoader

V/Corona  ( 9531): < Class.forName: plugin.chartboost.LuaLoader

 Loading via reflection: plugin.chartboost.LuaLoader

I/Corona  ( 9531): placeholder 1

I/Corona  ( 9531): chartboost was told to be cached****

systemEventfunction*******

I/Corona  ( 9531): chartBoostListener Called

I/Corona  ( 9531): Here!! *******[/lua]

In your event handler for chartboost you must check event.type and event.response to determine what to do next, otherwise weird things can start to happen as this handler gets called on many different occasions.
 
You can see a list of of possible listener events here:
https://github.com/swipeware/CoronaChartboostPlugin/blob/modernized/docs/init.markdown
 
A simple handler can look like this:

local function chartBoostListener( event ) if event.type == "interstitial" then if event.response == "cached" then print("Chartboost has cached ad") chartboost.show( "interstitial" ) end end end

You might need to turn off autocaching for the function above to work properly though, as a new ad will automatically be cached as soon as an ad is shown.
chartboost.autoCacheAds( false )

Thanks for the tips! I finally got around to testing it on a device but I must still be doing something wrong. Here’s what I’m working with now

I seem to be getting a failed event.response and after I try to call on my chartBoostListener after 5 seconds, my event.type = nil. I tried to cache my interstitial again within this function thinking that it will turn event.type into interstitial but unfortunately it did not. I’m kinda stuck on ideas except giving it more and more time to cache?

Also my print statement “test mark 4” isn’t coming up in terminal, I’m not sure if that’s an important factor. 

Thanks for any help, I appreciate it!

[lua]

local function chartBoostListener( event )

print (“test mark 1”)

print (event.type)

   if event.type == “interstitial” then

    print (“test mark 2”)

    print (event.response)

      if event.response == “cached” then

         print(“Chartboost has cached ad”)

         chartboost.show( “interstitial” )

         

       else 

       print (“test mark 3”) 

       

       timer.performWithDelay( 5000, chartBoostListener, 1)

       

       --chartBoostListener() 

       chartboost.cache( “interstitial” )

       print (“test mark 4”)

      end

      

   else

    print (“else statement”)

    print (event.type)   

   end 

end

local chartboost = require( “plugin.chartboost” )

print (“placeholder 1”)

chartboost.init {

        appID        = “54dff5ed43150f0f55d4639a”,

        appSignature = “22d7ec10c4d220a1c4f46b6fe19b9a834c0f3d8d”, 

        listener     = chartBoostListener

        --change listener to     adListenerFunction

    }

chartboost.autoCacheAds( false ) 

chartboost.cache( “interstitial” )

local function systemEvent( event )

    local phase = event.phase

print (“systemEventfunction*******”)

    if event.type == “applicationResume” then

        – Start a ChartBoost session after screen comes back from idle? and accurately allows chartboost to manage impressions/click rates

        print (“Start Chartboost session ******”)

        chartboost.startSession( “54dff5ed43150f0f55d4639a”, “22d7ec10c4d220a1c4f46b6fe19b9a834c0f3d8d” )

        --chartboostFunction()

    end

    

    return true

end

Runtime:addEventListener( “system”, systemEvent )

[/lua]

And here’s my terminal

[lua]

I/Corona  ( 1467): test mark 1

I/Corona  ( 1467): interstitial

I/Corona  ( 1467): test mark 2

I/Corona  ( 1467): failed

I/Corona  ( 1467): test mark 3

I/Corona  ( 1467): test mark 1

I/Corona  ( 1467): nil

I/Corona  ( 1467): else statement

I/Corona  ( 1467): nil

[/lua]

You should never call chartBoostListener() in your code yourself. It’s up to the chartboost library to do the calling. (this means you should remove your performWithDelay() function call)

Also, there is no guarantee that an ad will be cached when you call chartboost.cache(“interstitial”). The most common reason is that there’s no ad inventory to show for your device. If you get a “failed” event, check event.info to get more detailed info about why it failed. You can see a list of error codes in the link I provided in my previous post.

okay thanks ingemar, I’m a noob at this so I really appreciate it. I’ll put a little more work into it tomorrow and post it if I can get it to work. 

Edit: Actually I was curious to what event.info would say, so I went ahead and tested it. Terminal reads “NO_AD_FOUND”

which doesn’t exactly correlate to that list of errors on that link. Do you think that’s congruent with what you were thinking about no ads being available or most likely a problem on my end?

In your event handler for chartboost you must check event.type and event.response to determine what to do next, otherwise weird things can start to happen as this handler gets called on many different occasions.
 
You can see a list of of possible listener events here:
https://github.com/swipeware/CoronaChartboostPlugin/blob/modernized/docs/init.markdown
 
A simple handler can look like this:

local function chartBoostListener( event ) if event.type == "interstitial" then if event.response == "cached" then print("Chartboost has cached ad") chartboost.show( "interstitial" ) end end end

You might need to turn off autocaching for the function above to work properly though, as a new ad will automatically be cached as soon as an ad is shown.
chartboost.autoCacheAds( false )

Thanks for the tips! I finally got around to testing it on a device but I must still be doing something wrong. Here’s what I’m working with now

I seem to be getting a failed event.response and after I try to call on my chartBoostListener after 5 seconds, my event.type = nil. I tried to cache my interstitial again within this function thinking that it will turn event.type into interstitial but unfortunately it did not. I’m kinda stuck on ideas except giving it more and more time to cache?

Also my print statement “test mark 4” isn’t coming up in terminal, I’m not sure if that’s an important factor. 

Thanks for any help, I appreciate it!

[lua]

local function chartBoostListener( event )

print (“test mark 1”)

print (event.type)

   if event.type == “interstitial” then

    print (“test mark 2”)

    print (event.response)

      if event.response == “cached” then

         print(“Chartboost has cached ad”)

         chartboost.show( “interstitial” )

         

       else 

       print (“test mark 3”) 

       

       timer.performWithDelay( 5000, chartBoostListener, 1)

       

       --chartBoostListener() 

       chartboost.cache( “interstitial” )

       print (“test mark 4”)

      end

      

   else

    print (“else statement”)

    print (event.type)   

   end 

end

local chartboost = require( “plugin.chartboost” )

print (“placeholder 1”)

chartboost.init {

        appID        = “54dff5ed43150f0f55d4639a”,

        appSignature = “22d7ec10c4d220a1c4f46b6fe19b9a834c0f3d8d”, 

        listener     = chartBoostListener

        --change listener to     adListenerFunction

    }

chartboost.autoCacheAds( false ) 

chartboost.cache( “interstitial” )

local function systemEvent( event )

    local phase = event.phase

print (“systemEventfunction*******”)

    if event.type == “applicationResume” then

        – Start a ChartBoost session after screen comes back from idle? and accurately allows chartboost to manage impressions/click rates

        print (“Start Chartboost session ******”)

        chartboost.startSession( “54dff5ed43150f0f55d4639a”, “22d7ec10c4d220a1c4f46b6fe19b9a834c0f3d8d” )

        --chartboostFunction()

    end

    

    return true

end

Runtime:addEventListener( “system”, systemEvent )

[/lua]

And here’s my terminal

[lua]

I/Corona  ( 1467): test mark 1

I/Corona  ( 1467): interstitial

I/Corona  ( 1467): test mark 2

I/Corona  ( 1467): failed

I/Corona  ( 1467): test mark 3

I/Corona  ( 1467): test mark 1

I/Corona  ( 1467): nil

I/Corona  ( 1467): else statement

I/Corona  ( 1467): nil

[/lua]

You should never call chartBoostListener() in your code yourself. It’s up to the chartboost library to do the calling. (this means you should remove your performWithDelay() function call)

Also, there is no guarantee that an ad will be cached when you call chartboost.cache(“interstitial”). The most common reason is that there’s no ad inventory to show for your device. If you get a “failed” event, check event.info to get more detailed info about why it failed. You can see a list of error codes in the link I provided in my previous post.

okay thanks ingemar, I’m a noob at this so I really appreciate it. I’ll put a little more work into it tomorrow and post it if I can get it to work. 

Edit: Actually I was curious to what event.info would say, so I went ahead and tested it. Terminal reads “NO_AD_FOUND”

which doesn’t exactly correlate to that list of errors on that link. Do you think that’s congruent with what you were thinking about no ads being available or most likely a problem on my end?