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

Pass Leaderboard Id to score JSON objects #30

Merged
merged 2 commits into from Nov 12, 2020
Merged

Pass Leaderboard Id to score JSON objects #30

merged 2 commits into from Nov 12, 2020

Conversation

SkaterDad
Copy link
Contributor

Hello!

I came across a use case for getting leaderboard scores, and noticed the Leaderboard ID was not part of the callback data.

This PR proposes to pass along the String leaderboardId with the LeaderboardScore, and adding a leaderboard_id key to the JSON object. This allows us to know which leaderboard we're dealing with in Lua.

I've tested this on a published game with my phone. The changes are simple, so I expect it will not have issues.

Example:

-- somewhere, querying 2 leaderboards

	gpgs.leaderboard_get_player_score(LEADERBOARD_ID, gpgs.TIME_SPAN_ALL_TIME, gpgs.COLLECTION_PUBLIC)
	gpgs.leaderboard_get_player_score(HIGHLEVEL_ID, gpgs.TIME_SPAN_ALL_TIME, gpgs.COLLECTION_PUBLIC)

-- in the callback

	elseif message_id == gpgs.MSG_GET_PLAYER_SCORE then
		if not message.error and message.score then
			local gpgs_score = tonumber(message.score)

			-- If GPGS high score > current game score, apply it!
			if message.leaderboard_id == LEADERBOARD_ID then
				if gpgs_score > savedata.stats.high_score then
					savedata.update_score(gpgs_score)
				end
			-- If GPGS high level > current game level, apply it
			elseif message.leaderboard_id == HIGHLEVEL_ID then
				if gpgs_score > savedata.stats.high_level then
					savedata.update_level(gpgs_score)
				end
			end
		end

@britzl
Copy link
Contributor

britzl commented Nov 12, 2020

Good improvement! Thanks.

@britzl britzl merged commit 323402c into defold:master Nov 12, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants