kloder-games / godot-admob

Module Admob for Godot engine
MIT License
360 stars 61 forks source link

Rewarded video function to get reward #103

Open burakgulmez opened 5 years ago

burakgulmez commented 5 years ago

OS target: Android Godot version: 3.1 In _on_rewarded(currency, amount) function, what is currency and amount? Are they variable name in game? For example my game character has a variable named health. Should i write "health" to currency? How can i code the player gets reward after watching video? How can I connect variable and the rewarded function?

Shin-NiL commented 5 years ago

These values are defined in the Admob backend. When the _on_rewarded callback is called, you'll get these values as the currency and amount arguments. So if on the Admob backend (Admob site) you've defined the string coin for currency and 5 for value and you call:

_on_rewarded(currency, amount):
    print(currency) # will print "coin"
    print(value) # will print "5"
burakgulmez commented 5 years ago

If I write the code:

admob.showRewardedVideo()
$Player.health = 100

I cannot be sure the person watched the reward video. The person will get 100 health.

I tried this:

if admob._on_rewarded("$Player/health", 100):
   $Player.health = 100

but it doesnt work. Because it doesnt return true or false, and the parameters are false i think.

Shin-NiL commented 5 years ago

First, you shouldn't pass the current and amount arguments, they will be returned from the admob server.

Second, you must call func _on_rewarded(currency, amount) and not admob._on_rewarded

Third, if the _on_rewarded is called it means the person watched the video, no need for a Boolean return here.

Please check the example code and the readme file to see how it works.

gumaciel commented 4 years ago

@burakgulmez issue still persists?

nyelare commented 3 years ago

Why my on_rewarded(currency, amount) show this error Parser Error: The identifier "currency" isn't declared in the current scope. `func _on_reward_pressed():

if Ads.is_rewarded_video_loaded():
    Ads.show_rewarded_video()
    Ads._on_rewarded(currency, amount)
    print(currency)
    print(amount)`

I define in Admob site. reward type is money and amount is 10000

I hope you will help me with this. Thank you

gumaciel commented 3 years ago

Hey @nyelare , this function is a "callback function" this mean when AdMob receives a rewarded he will call this function into your game project, like this:

https://github.com/kloder-games/godot-admob/blob/master/examples/godot-3/main.gd#L108-L110

Please use the example project to see how module works: https://github.com/kloder-games/godot-admob/blob/master/examples/godot-3/

nyelare commented 3 years ago

@gustavottc okay thank you! I already got it <3