Sign-in callbacks don't work
The module works, I sign-in, submit and retrieve leaderboard score successfully. Yet, sign-in and is_player_connected callbacks don't work. I've tried some simple print("something") statements and no output. Leaderboard submission callbacks work - I get feedback from the print statement approach.
After some additional testing: If there is a problem with the auth (wrong sha1 or user just declines google permissions request to use google drive, etc), _on_sign_in_failed callback works and returns an error code. If sign-in is successful, _on_sign_in_success is not called. If the phone is not connect to the internet, the sign-in is still successful - I guess GPGS client libraries do some kind of caching/proxying for the internet connection.
Also, _on_player_is_already_connected doesn't get called (I'm trying to call is_player_connected() somewhere after sign_in()).
My idea is to use is_player_connected to determine if some score related gui itens will be visible or not.
Not sure if you have figured this out yet, but for anyone else having this problem it would appear that the function _on_sign_in_success() actually requires a parameter in order to be recognized. So the following does work successfully:
(Note: I prefer to use typed GDScript, so the extra "fluff" can be removed if you want)
func _on_sign_in_success(id : String) -> void:
print("hello from _on_sign_in_success\nID: %s" % id)
The id parameter that is given looks to be the ID for the Google User.
Similarly, the callback for _on_player_is_already_connected() requires 2 parameters. So the following will work:
func _on_player_is_already_connected(status : bool, id : String) -> void:
print("hello from _on_player_is_already_connected\nStatus: %s | ID: %s" % [status,id])
The status parameter is either true or false depending on if the user is connected or not, and the id contains the ID once again and should match the one from _on_sign_in_success(). Hope this helps!
I've ended up releasing my game without using this function. But I would like to use on my next one so, this is extremely useful. How can I know the user ID for checking if he signs in successfully? Do I have to provide the ID when signing in, or is the ID provided by the callback _on_sign_in_success? Thank you!
@cgeadas I have updated Read me. You can check the correct callback. You don't need to provide the id when signing in. Correct signature of the _on_sign_in_success callback is: func _on_sign_in_success(account_id: String) -> void
Please try again and check if it is working now. Keep in mind to download the latest plugin from tag 1.2.0 (https://github.com/cgisca/PGSGP/releases/tag/1.2.0).
EDIT: I'm submitting an official request to change is_player_connected() to immediately return a result (synchronous) rather than use a callback (asynchronous).
I'm encountering an issue where my app works fine when loaded from Android Studio but does not work when installed from the Play Store. The issue is the spaghetti-code I've had to write just because is_player_connected() uses a callback. The problem is normal code branching based upon the return from is_player_connected() can't be used because of the callback strategy.
Ideally I should be able to write
func _ready():
If !gpgs.is_player_connected():
gpgs.sign_in();
else:
# do other stuff...
@cgisca _on_sign_in_success callback is working ok. However, is_player_connected never triggers the callback. On a side note, I agree with @tx350z about synchronous results. If it is possible to make it synchronous, it would make my programming much simpler and "clean" than going around with weird gymnastics because of the callbacks. But then, if it programmed like this, it's because it probably has to be like this.
Actually it doesn't have to use callbacks for everything. I added synchronous versions of is_player_connected(), save_snapshot(), and load_snapshot() to the plug-in Java code.
@tx350z I (still) don't speak Java :-) so I can't adapt it completely to my needs. Meanwhile, I'll try to deal with the callbacks with a mix of signals and yields - maybe that can work in a manageable way - meaning I'll still be able to understand my code in a few months from now.
Be aware that yield() will not be included in Godot 4.0. Hopefully there will be something similar to allow cooperative multi-threading.
@tx350z Thank you for the heads up. I was not aware of that change. I really hope they come up with something useful - sometime those guys are so short-sighted... :-(
_on_player_is_already_connected
I can not a find a signal for this...