Leaderboards

GD-Sync includes a built-in leaderboard system that allows users to submit scores to global leaderboards and compete with other players.

To use leaderboards, first create a database in the control panel. Once the database is created, go to your API key and link the database to it.

GD-Sync’s leaderboard system revolves around the built-in player account system. Only players that are logged-in can use leaderboards. Please look at Cloud Storage for more information.

Scores

To submit a score to a leaderboard, use GDSync.leaderboard_submit_score(leaderboard : String, score : int). This returns a response code from ENUMS.LEADERBOARD_SUBMIT_SCORE_RESPONSE_CODE.

To delete a score from a leaderboard, use GDSync.leaderboard_delete_score(leaderboard : String). This returns a response code from ENUMS.LEADERBOARD_DELETE_SCORE_RESPONSE_CODE. Scores can also be removed directly from the control panel.

Each user can only have one score on a leaderboard, and submitting a new score will overwrite the previous one.

A valid login session is required for the score to be accepted.

func _ready():
	var response_code : int = await GDSync.leaderboard_submit_score("Leaderboard1", 100)
	
	if response_code == ENUMS.LEADERBOARD_SUBMIT_SCORE_RESPONSE_CODE.SUCCESS:
		print("Score submitted!")
	else:
		match(response_code):
			ENUMS.LEADERBOARD_SUBMIT_SCORE_RESPONSE_CODE.NO_RESPONSE_FROM_SERVER:
				push_error("No response from server")
			ENUMS.LEADERBOARD_SUBMIT_SCORE_RESPONSE_CODE.DATA_CAP_REACHED:
				push_error("Data transfer cap has been reached.")
			ENUMS.LEADERBOARD_SUBMIT_SCORE_RESPONSE_CODE.RATE_LIMIT_EXCEEDED:
				push_error("Rate limit exceeded, please wait and try again.")
			ENUMS.LEADERBOARD_SUBMIT_SCORE_RESPONSE_CODE.NO_DATABASE:
				push_error("API key has no linked database.")
			ENUMS.LEADERBOARD_SUBMIT_SCORE_RESPONSE_CODE.NOT_LOGGED_IN:
				push_error("There is not valid login session.")
			ENUMS.LEADERBOARD_SUBMIT_SCORE_RESPONSE_CODE.STORAGE_FULL:
				push_error("The database is full.")
			ENUMS.LEADERBOARD_SUBMIT_SCORE_RESPONSE_CODE.LEADERBOARD_DOESNT_EXIST:
				push_error("The leaderboard does not exist.")
  

Browsing

Leaderboards and their submitted scores can be browsed using GDSync.leaderboard_browse_scores(leaderboard : String, page_size : int, page : int). This returns a dictionary in the defined format, along with a response code from ENUMS.LEADERBOARD_BROWSE_SCORES_RESPONSE_CODE. GD-Sync also includes a built-in template that demonstrates how to create a leaderboard browser.To retrieve the score and rank of a specific user, use GDSync.leaderboard_get_score(leaderboard : String, username : String). This returns a dictionary in the defined format, with a response code from ENUMS.LEADERBOARD_GET_SCORE_RESPONSE_CODE.

A valid login session is required to browse and retrieve scores.

{
	"Code" : 0,
	"FinalPage": 7,
	"Result" : 
		[
			{"Rank": 1, "Score": 828, "Username": "User1"},
			{"Rank": 2, "Score": 700, "Username": "User2"},
			{"Rank": 3, "Score": 10, "Username": "User3"}
		]
}
  
{
	"Code" : 0,
	"Result" : 
		{
			"Score" : 100,
			"Rank" : 1
		}
}