Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for await keyword in the Godot SDK #58

Open
treepumpkin opened this issue Oct 28, 2024 · 1 comment
Open

Support for await keyword in the Godot SDK #58

treepumpkin opened this issue Oct 28, 2024 · 1 comment

Comments

@treepumpkin
Copy link

Godot 4 introduced the await keyword for coroutines, it would be nice to use it in this SDK, too. Here is an example with the login_as_new_guest_user call.

Current SDK usage:

func _ready():
	
	# Get the SDK and Init
	self.aws_game_sdk = get_node("/root/AwsGameSdk")
	self.aws_game_sdk.init(self.login_endpoint, self.on_login_error)
	
	# Log in as new guest user first
	self.aws_game_sdk.login_as_new_guest_user(self.login_as_guest_callback)

# Called on any login or token refresh failures
func on_login_error(message):
	print("Login error: " + message)

# Receives a UserInfo object after successful guest login
func login_as_guest_callback(user_info):
	print("Received guest login info.")
	print(user_info)

	# Try linking Steam ID to existing user
	# NOTE: You need to use the Godot Steamworks SDK (https://godotsteam.com/) to integrate with Steam
	#       Use the GetAuthTicketForWebAPI to get the steam auth token (https://godotsteam.com/functions/users/#getauthticketforwebapi)
	self.aws_game_sdk.link_steam_id_to_current_user("YourTokenHere", self.on_link_steam_id_response)
	

Desired SDK usage (same pattern as in W4 Cloud's SDK )

func _ready():

	# Get the SDK and Init
	self.aws_game_sdk = get_node("/root/AwsGameSdk")

	var res = await self.aws_game_sdk.login_as_new_guest_user().async()

	if res.is_error():
		print("Error!:" + res.as_error())
		return

	print("Received guest login info.")
	print(res.get_data())

	# Try linking Steam ID to existing user
	# NOTE: You need to use the Godot Steamworks SDK (https://godotsteam.com/) to integrate with Steam
	#       Use the GetAuthTicketForWebAPI to get the steam auth token (https://godotsteam.com/functions/users/#getauthticketforwebapi)
	res = await aws_game_sdk.link_steam_id_to_current_user("YourTokenHere").async()
@juhoaws
Copy link
Contributor

juhoaws commented Oct 28, 2024

Interesting, thank you for pointing this out. Does the await here yield the execution back and return to this function only after the response comes in? Quick look at the docs it looks like that's the case. The other thing I'd need to investigate is the async() call for a method, is that something that needs to be implemented on the method level?

If you're interested in working on a pull request on this, we'd be happy to include that! But completely fine if not, we'll keep it in the issues then and try to come back to this at a later point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants