DrMoriarty / godot-applovin-max

AppLovinMax plugin for godot engine.
27 stars 7 forks source link

I don't understand how callbacks should be set up #14

Open ayhanasker opened 2 years ago

ayhanasker commented 2 years ago

Hello, I need callbacks, so I need to perform ad showing and scoring, but I don't understand how to do this. For example I try (in applovin_max.gd):

func _on_rewarded_video_ad_loaded(id: String)-> void: $debug.text = "ok : "+String(id) func _on_rewarded_video_started(id: String)-> void: $debug.text = "rewarded video ad started" pass func _on_rewarded_video_completed(id: String)-> void: $debug.text = "rewarded video ad completed" pass func _on_rewarded(id: String, reward: String, amount: int)-> void: $debug.text = "on rewarded" pass .. no results are returned.

I also tried the following in the _ready() function. ads.connect ( " on_rewarded_video_adloaded" self, " on_rewarded_video_ad_loaded") ads.connect ( " on_rewarded_video_ad_failed_toload" self, " on_rewarded_video_ad_failed_to_load") ads.connect ( " on_rewarded_videostarted" self, " on_rewarded_video_started") ads.connect ( " on_rewarded_video_ad_closed" self,"_on_rewarded_video_ad_closed") _ads.connect("_on_rewarded_video_completed",self,"_on_rewarded_video_completed") _ads.connect("_on_rewarded",self,"_on_rewarded")

Buddha failed. I may be a little clumsy :) It would be nice if there was a small example of how to do it. Thank you

Muserato commented 2 years ago

This was not fully obvious to me either, but this is what you want to do: Leave Applovin_max.gd alone, that is your singleton and if you modify it, it will get overwritten if you ever update the plugin. in your script, when you call for the loading of one of the ad types, you define which node is getting the callback. Like in the example provided:

applovin_max.loadBanner("zone_id", true, self.get_instance_id())

That last argument (self.get_instance_id()) lets the plugin know which node should be notified with the callbacks. Then you wan to put your callback function (e.g. func _on_banner_loaded(id: String)) in the script for that node as well. So something like the following in a single script:

func ready() -> void: applovin_max.loadBanner("zone_id", true, self.get_instance_id())

func _on_banner_loaded(id: String) -> void: your code here

The zone_id being the id of your ad unit from AppLovin Max. You do not need to connect signals

ayhanasker commented 2 years ago

thanks. I get it now :)