I’m trying to load Facebook instant game ads as below,
-- Preload ad unit
function load_ad_unit(ad_unit_id)
print("loading ad unit...")
fbinstant.load_interstitial_ad(
ad_unit_id,
function(self, success)
if success then
print("Ad unit successfully loaded ")
else
print("Ad unit doesn't loaded ", ad_unit_id)
end
end
)
end
-- Show ad unit
function show_ad_unit(ad_unit_id)
fbinstant.show_interstitial_ad(
ad_unit_id,
function(self, success)
if success then
print("Ad unit successfully opened ", ad_unit_id)
else
print("Ad unit doesn't opened ", ad_unit_id)
end
end
)
end
function on_message(self, message_id, message, sender)
if message_id == hash("NEW_GAME") then
load_ad_unit("<ad_unit_id>")
elseif message_id == hash("ON_PRESS") then
show_ad_unit("<ad_unit_id>")
end
end
But this only works once at the beginning of the game when I press a button. For the second time it doesn’t work. So I tired to load the ad unit again and it throws ADS_TOO_MANY_INSTANCES.
Don’t hold on to too many AdInstances: Both methods getRewardedVideoAsync or getInterstitialAdAsync return an AdInstance which can be preloaded. Preloading 3 or more AdInstances without showing them will cause subsequent attempts of creating a new AdInstance to fail. This means that calls to getRewardedVideoAsync and getInterstitialAdAsync will start to fail with error code ADS_TOO_MANY_INSTANCES until showAsync is called or until the player restarts Messenger.
There could potentially be a bug in the extension code as well. This is where references to ad instances are kept and removed:
Yes, I already checked those library files including JS and CPP and I can see there are only 4 module methods for the Ads in fninstalt.cpp:1564.
Those are not relevant to get an ad instant. Still, I couldn’t find a solution for this, at least how to get the instant of a loaded Ad in Lua script and show it instead of trying to load it again. I just need to show this loaded ad several times.
Below are errors that occur in most situations,
> FBInstant_PlatformShowInterstitialAdAsync - unable to find ad. Did you load it?
> FBInstant_PlatformLoadInterstitialAdAsync - error a {code: "ADS_NO_FILL", message: "No fill"}
> FBInstant_PlatformLoadInterstitialAdAsync - error a {code: "ADS_TOO_MANY_INSTANCES", message: "Too many ad instances"}
Yes they are. The load_interstitial_ad() will call into the javascript code to get an ad instance and keep a reference to it in the javascript part of the extension. When you call show_interstitial_ad() it will take one of the loaded interstitial ads and show it (and then throw away the reference to it so that it gets garbage collected).
I don’t think that’s how it works. You can only show a loaded ad instance once. When it has been shown you need to load a new one. Please correct me if I’m wrong!
Well, it’s clear now. One last thing, is there any way that I can catch the error and handle it? So I can check the error code and load ad new ad if ad instant not exists.
The reason here is, I’m showing the ad when a player presses a button. So a player can be press the button too many times. Every time when he press the button the Ad should be shown. So I changed my show_ad_unit function as below. Now it’s loads a new Ad after success.
-- Show ad unit
function show_ad_unit(ad_unit_id)
fbinstant.show_interstitial_ad(
ad_unit_id,
function(self, success)
if success then
print("Ad unit successfully opened ", ad_unit_id)
-- * I put this here because `show_interstitial_ad`
-- handles removing the ad instance
load_ad_unit(ad_unit_id)
else
print("Ad unit doesn't opened ", ad_unit_id)
end
end
)
end
This also not working. I keep getting these errors,
> FBInstant_PlatformLoadInterstitialAdAsync - error a {code: "ADS_NO_FILL", message: "No fill"}
> FBInstant_PlatformLoadInterstitialAdAsync - error a {code: "ADS_TOO_MANY_INSTANCES", message: "Too many ad instances"}
And is there any issue with that I keep using one placement ID for this?
Can I listen to the on-close event of an Ad? (To load a new one)
Is there any way that I can catch errors thrown by the fbinstant module?
Ads only work for me when I precede each load interstitial function with a get interstitial ad function. Is that how it should be or should we get only once on init then load several times with the same id returned from get?