I want to warn my players about the ad with countdown 3 2 1 but its seems it doesnt work porperly
ADmanager
extends Node
var can_show_ad: bool = false
onready var popup = get_node("/root/Game/Control/Label")
onready var animation_player = get_node("/root/Game/Control/AnimationPlayer")
signal set_mobile
signal set_desktop
func _ready() -> void:
reset_ad_timer()
Bridge.advertisement.connect("interstitial_state_changed", self, "_on_interstitial_state_changed")
Bridge.game.connect("visibility_state_changed", self, "_on_visibility_state_changed")
var device_type = Bridge.device.type
if device_type == "mobile" or device_type == "tablet":
emit_signal("set_mobile")
else:
emit_signal("set_desktop")
func _on_visibility_state_changed(state):
if state == "hidden":
pass
else:
pass
func reset_ad_timer() -> void:
can_show_ad = false
yield(get_tree().create_timer(5), "timeout")
can_show_ad = true
func _on_interstitial_state_changed(state):
print("State: ", state)
if state == "closed" or state == "failed":
reset_ad_timer()
popup.visible = false
elif state == "opened":
popup.visible = false
else:
pass
func show_ad_warning() -> void:
popup.visible = true
yield(get_tree().create_timer(3), "timeout")
show_ad()
func show_ad() -> void:
if can_show_ad:
Bridge.advertisement.show_interstitial()
else:
print("Ad cannot be shown yet")
# Call this function when you want to show an ad
func try_show_ad() -> void:
if can_show_ad:
adcount()
show_ad_warning()
else:
print("Ad not ready")
func adcount():
if animation_player:
animation_player.play("ad")
Part of my main code
func _on_draw_finished():
if error_change_direction or abs(angle_covered) < 340.0:
if score_label:
score_label.text = "It's not a circle"
custom_points = []
return
var perfection_score = calculate_perfection()
update_score(perfection_score)
Admanager.try_show_ad()
My ad manager is in the autoload and my countdown is an label and i make countdown with animation player and thats not playing always in 3 and i tried my ads and after 2 time its doesnt appears.I will be happy for any help
I dont quite understand how your time countdown works because I dont see a timer being run or a _process() method adding the delta to the elapsed time.
What is currently happening with the current state of the code?
As you are working with delays, the whole program is forcefully stopped for 5seconds, then the ad comes in an instant.
thats not playing always in 3 and i tried my ads and after 2 time its doesnt appears.I will be happy for any help
So sometimes your ad plays and sometimes it doesnt?
Only 1 time at first then only appears my warning but ad no, and i am using yield not func process and in that time i am playing my animation 3 2 1 and then playing my ad
What is happening in this animation?
Can you wait for the completion of the animation instead of yielding in your show_ad_warning() method?
For example yield(animation_player, "animation_finished").
I am not a fan of forcefully yielding so I am unsure if this works but you can try it out.
func adcount():
if animation_player:
animation_player.play("ad")
yield(animation_player, "animation_finished")
i would put a breakpoint and see if the code progression is halted while the animation is playing.
I am sadly not that proficient in Godot3 so i am just using yield similar to await.
You need to find out how your code is progressing and then find out what’s causing the animation to be halted. Ideally the code should yield until the animation finished
func show_ad_warning() -> void:
popup.visible = true
adcount()
func show_ad() -> void:
if can_show_ad:
Bridge.advertisement.show_interstitial()
else:
print("Ad cannot be shown yet")
# Call this function when you want to show an ad
func try_show_ad() -> void:
if can_show_ad:
adcount()
show_ad_warning()
else:
print("Ad not ready")
func adcount():
if animation_player:
animation_player.play("ad")
yield(animation_player, "animation_finished")
show_ad()
I believe your code progression is try_show_ad() → adcount() → show_ad() → Bridge.advertisement.show_interstitial()
and your label (aka: popup) is countdowned inside of the animation.
How do you currently show the ad warning?
It’s the popup, right? onready var popup = get_node("/root/Game/Control/Label")
But where do you set the text? popup.text = 3?
Because I don’t know what’s inside animation_player.play("ad"), i believe you set the text of the popup inside it, wait 1second, then set the text to 2 … until you reach 0.
The animation is your countdown that shows your popup, right?
After the countdown reaches 0, then you go to show_ad().
func show_ad_warning() -> void:
popup.visible = true
adcount()
func show_ad() -> void:
if can_show_ad:
Bridge.advertisement.show_interstitial()
else:
print("Ad cannot be shown yet")
# Call this function when you want to show an ad
func try_show_ad() -> void:
if can_show_ad:
adcount()
else:
print("Ad not ready")
func adcount():
if animation_player:
animation_player.play("ad")
yield(animation_player, "animation_finished")
show_ad()
okay, I believe you can add the popup.visible = true statement into your animation.
You can add the visible attribute of your popup Label to your animation and set it to true right at the start. You can also set it to false at the end of the animation to hide it.
Maybe rename the animation into “ad_countdown”, otherwise I would have thought you are showing the ad as an animation.
Okay i will rename it and make visible and invisible in my animation but now its dont even shows up my 3 2 1 I have deleted that function show ad … I think thats the problem
That doesn’t matter for now, I need you to check if the code goes into the adcount() method and if the animation is played as defined in the AnimationPlayer. You can create a Breakpoint at the line that says if animation_player: and then go line-by-line and see if if the ad countdown animation is playing.
if you believe that the visible attribute is not correctly set in the animation, you can just make the label visible in the editor and see if the countdown works.
You need to monitor your Remote tab in concern to the variables of Admanager.
Does it go into adcount()? What is the value of can_show_ad? What happens in Bridge.advertisement.show_interstitial() and can you do it twice?
If i set breakpoint at that adcount function if animation… And then its stops doestn that mean that my adcount function works? And the other things sadly i cant show because its late in my country, sorry.