godotengine / godot-ios-plugins

MIT License
126 stars 48 forks source link

request_achievements and request_achievement_descriptions not working? #38

Closed theaveragegeek closed 1 year ago

theaveragegeek commented 1 year ago

Working in Godot Version 3.4.2, and it seems the request_achievements() and request_achievement_descriptions() functions are both not working for me.

Based on the readme and this documentation I'd expect the request_achievements function to make a dictionary containing the names of all the GameCenter achievements and the progress on each one.

However, currently getting an error when using this from Xcode; the value of gc_scores is always null

SCRIPT ERROR: Invalid get index 'result' (on base: 'Nil').
   at: init (res://AppStore.gdc:26) - Invalid get index 'result' (on base: 'Nil')

Here is my code:

func init():
    var gc_scores = game_center.request_achievements()
    if gc_scores["result"] == "ok":
        print("Success!")
    else:
        print("Failure!")
    achievements_update()

func _process(_delta):
    test_GC_scores = game_center.request_achievement_descriptions()
    if test_GC_scores != null:
        print("Success")

This is all from the AppStore.gd script, the init function is called by the ready function of a different script, and the game_center variable is initialized at the beginning of AppStore.gd and is authenticated in the ready function of that script.

The code in the process function is for testing purposes only(I wouldn't want this to be run every frame), but I was thinking maybe the init function was called before the game_center variable finished authenticating, but the "Success" never gets printed.

naithar commented 1 year ago

Calling request_achievements and request_achievement_descriptions do not return anything (void result). They create events, that should be handled by get_pending_event_count and pop_pending_event. Example on how to do it is described here: https://docs.godotengine.org/en/stable/tutorials/platform/ios/plugins_for_ios.html#asynchronous-methods

theaveragegeek commented 1 year ago

Ah okay, that worked. Sorry, looks like I missed the top part of this documentation, thanks!