GithubHelp home page GithubHelp logo

Comments (1)

gumaciel avatar gumaciel commented on July 20, 2024 1

Hi, your code is not wrong, but you are noticing this because you are not waiting for the reward_ad to be loaded to click on the button, I did some modifications for you:

extends Button

var rewarded_ad : RewardedAd
var rewarded_ad_load_callback := RewardedAdLoadCallback.new()
var on_user_earned_reward_listener := OnUserEarnedRewardListener.new()
var _full_screen_content_callback := FullScreenContentCallback.new()

@export var reward_type : String
@export_category("skin")
@export var skin_name : String

func _ready():
	rewarded_ad_load_callback.on_ad_failed_to_load = on_rewarded_ad_failed_to_load
	rewarded_ad_load_callback.on_ad_loaded = on_rewarded_ad_loaded
	on_user_earned_reward_listener.on_user_earned_reward = on_user_earned_reward
    _full_screen_content_callback.on_ad_dismissed_full_screen_content = func() -> void:
        your_button.disabled = true
		if _rewarded_ad:
			_rewarded_ad.destroy()
			_rewarded_ad = null
		load_ad()
	your_button.disabled = true
	load_ad()

func load_ad() -> void:
	var unit_id : String
	if OS.get_name() == "Android":
		unit_id = "ca-app-pub-3940256099942544/5224354917"
	elif OS.get_name() == "iOS":
		unit_id = "ca-app-pub-3940256099942544/1712485313"
 
	RewardedAdLoader.new().load(unit_id, AdRequest.new(), rewarded_ad_load_callback)

func on_rewarded_ad_failed_to_load(adError : LoadAdError) -> void:
	print(adError.message)
	
func on_rewarded_ad_loaded(rewarded_ad : RewardedAd) -> void:
	print("rewarded ad loaded " + str(rewarded_ad._uid))
	self.rewarded_ad = rewarded_ad
	self.rewarded_ad.full_screen_content_callback = _full_screen_content_callback
	your_button.disabled = false

func on_user_earned_reward(rewarded_item : RewardedItem): # not using rewarded_item
	print("on_user_earned_reward, rewarded_item: rewarded", rewarded_item.amount, rewarded_item.type)

func _on_pressed():
	if rewarded_ad:
		rewarded_ad.show(on_user_earned_reward_listener)

please always check the documentation and the code in the sample:
https://poing-studios.github.io/godot-admob-plugin/ad_formats/rewarded/
https://github.com/poing-studios/godot-admob-plugin/blob/v3.1.0/addons/admob/sample/Rewarded.gd

from godot-admob-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.