How do I get the Facebook Instant Games Plugin to get rid of an Ad Instance once it’s shown? I’m following the tutorial here. [http://phaser.io/tutorials/facebook-instant-games-ads](http://Facebook Instant Games Ads) All works fine on first go round, but after successfully showing an ad, all the listeners are now doubled and it results in the error
"“PENDING_REQUEST”, message: “There is currently a pending request for locking message: showadasync”
Calling .destroy() on the ad instance causes game to crash in live testing. Removing all listeners doesn’t help. It’s like something is not registering that the ad has shown, even though the “shown” property is true.
I’m really trying hard to use the Facebook Instant Games Plugin but so far it is nothing but headache and errors, and no response from any forums anywhere.
Hmm, that error is coming from the Facebook SDK (it’s not a Phaser internal error). I’ve made quite a few updates to the FB plugin today, which are all in the master branch on GitHub and would be worth building from and using. Even so, I’m not entirely sure it will resolve your issue.
Once an ad has been displayed you just wait for the ad to finish and return control to your game. The instance doesn’t need destroying, indeed it doesn’t even have a destroy function to call, hence the erro), but you should be careful not to double-up any local event handlers you’ve got.
Thanks for your response! I appreciate it. I understand that it’s coming from Facebook SDK, it’s like it’s not reading that it has been shown. So, to recap, this is what I do. (Based on the tutorial). I’m probably missing an obvious step. Here’s a trimmed down version of what I’m doing.
show_ad()
{
console.log('called show_ad');
this.facebook.showAd('*******************************');
this.facebook.once('adfinished', function () {
console.log('ad finished');
scA.delay_to_next_ad(30);
});
this.facebook.once('adshowerror', function (error) {
console.log('ad show error');
console.log(error);
});
Load another add
delay_to_next_ad(delay_to_reload)
{
setTimeout(load_ad, delay_to_reload*1000);
function load_ad()
{
scA.load_an_ad();
}
}
It’s on the second go-round that I get the doubling up error and ‘ad loaded’ is called twice. I have tried removing the listener like this, but that does not good. (Which might be the completely wrong way to remove a listener).
this.facebook.off('adloaded');
Disclaimer: I am a self-taught duct tape programmer, I’m sorry if I’m completely misusing your code.
Hi - the problem is the way you’re removing the listener. You’ve bound the event to an anonymous function, so you can never ‘unbind’ this event again, either, because you can’t pass the same function to the ‘off’ method. The way to do it is to use a proper named function for your listener, then you can remove it again safely and it will stop this doubling-up you’re seeing.
Also, be aware there are rate limits in place that will prevent ads from being shown too close together. Although that won’t cause the event doubling issue, it will prevent the second ad from showing. You’ll get a rate limit error though.
Thanks a million for your response. I really do appreciate it. However, I still can’t kill off that God-forsaken listener to save my soul. I will keep at, though. I’m sure I’m not removing the listener right, and excuse my lack of programming knowledge but I just can’t figure out how I’m supposed to “write a proper named function for your listener” I’m just following the tutorial like a good monkey. If you could be a sweetie and someday add the removal process to the tutorial it might helpful In the meantime, if someone could shoot me an example of how it’s done that would be awesome! But I will keep at it regardless and post my conclusions.
Unfortunately, my solution ended up being to just use the Facebook implementation already, which after spending 3 days on this, I got set up and launched in under 20 minutes.
I managed to get rid of all the listeners, but the problem remains that when showAd() is called I get the error: "“PENDING_REQUEST”, message: “There is currently a pending request for locking message: showadasync”.
It’s as if it’s not clearing the ad once it’s shown, even though the parameter on the Ad Instance says “shown:true”.
I’m using the Phaser Instant Games Plugin for everything else in my games, so I really wanted to make this work to keep things consistent. Also, I find it just all around more pleasant and streamlined to work with. All in all, I love it!
If anyone’s managed to make the ads portion work, maybe you could post it here or in the forum somewhere. Thanks!!