- Home /
How to get the user score value from Google Play Services Leaderboard?
I know this is the basic of posting the score :
Social.ReportScore(TheScore, "LeaderboardID", (bool success) => {
// handle success or failure
});
But how do I "get" the score to be displayed again within the game? the problem is that whenever I update my app on Play Store, the local score returns to "0", but the ones on the Google Play Service Leaderboard is still intact, so I am looking for a way to get that Leaderboard value back to the game.
thx :)
Hello,
Any updates to this? I used to be able to Get Score using Android Native Plugin, but there must be a way that works without it.
Why does everyone seem to use a plugin for this?
Its all explained on the second page of the First Google Dev tutorial.
1.5k people have viewed this post. Still no answers.. this does not look promising. If anyone knows the answer please post (ideally without necessitating use of native code). This is pretty big feature to be missing from play services since you can't keep the game properly in sync.
Is there someone who did this already? Seems like they have implemented this feature, haven't they?
Answer by Virdari · Oct 15, 2015 at 11:24 AM
For those of you who are trying to get the leaderboard score from Google Play try this code after you're authenticated:
PlayGamesPlatform.Instance.LoadScores (
<your_leaderboard_ID_here>,
LeaderboardStart.PlayerCentered,
1,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(LeaderboardScoreData data) => {
Debug.Log (data.Valid);
Debug.Log (data.Id);
Debug.Log (data.PlayerScore);
Debug.Log (data.PlayerScore.userID);
Debug.Log (data.PlayerScore.formattedValue);
});
}
Basically, data.PlayerScore.UserID will give you the player's unique ID, data.PlayerScore.formattedValue will give you the highest score of the player that was submitted to the Google Play leaderboards. data.Id will give you the leaderboard ID and so on.
The retieved value from "data.PlayerScore.value" is always 0... im trying this code:
public void UpdateCoin$$anonymous$$erBoard(int coinsCollected){
$$anonymous$$erboardScoreData data = new $$anonymous$$erboardScoreData (leaderboard_coin_collector);
long retrievedScore = data.PlayerScore.value;
long total = retrievedScore +(long)coinsCollected;
Social.ReportScore(total,leaderboard_coin_collector, (bool success) => { });
}
I need to get the current coins and then increment that value.... but "retrievedScore" is always 0
This method works, and allows you to retrieve the local user score without having to display the built in leaderboard, useful for displaying the current high score on your in game UI.
You will need to add the following using statements for it to work as posted though.
using GooglePlayGames;
using GooglePlayGames.BasicApi;
I need help in getting the player nickname (like Bob, Andrew, Christopher) of the player in the leaderboard of my game. When I use loadScores, I only get the playerID( which is a string numbers), I tried to use loadPlayers and use alias, it doesn't give me anything. I can successfully logged in in google play game services. Like:
//1
FirstNickName.text = data.Scores[0].userID;
//2
SecondNickName.text = data.Scores[1].userID;
//3
ThirdNickName.text = data.Scores[2].userID;
etc...
Answer by meat5000 · Apr 20, 2016 at 11:12 AM
Seriously, this is not a Unity question, its a Google one.
The STARTING page of the Google Dev quickstart deals with Achievements and leaderboards.
https://developers.google.com/games/services/android/quickstart
Do the sample project. It will take half an hour. By the end of it you will know how leaderboards work and how to use them in your project.
Answer by Coder Gogoi · Aug 14, 2014 at 08:05 AM
You have to call Leader biard display methodt o get the Leader board score on your game.
Set up you leader biard on Google Play Game Service. just go through. https://developers.google.com/games/services/common/concepts/leaderboards
Use the Google play Plugins : https://github.com/playgameservices/play-games-plugin-for-unity
You can use the following method to call leader board. It is working in my case.
using UnityEngine;
using System.Collections;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
public class _GameCenterManager : MonoBehaviour {
// Use this for initialization
void Start () {
AuthonicatePlayer();
}
private void AuthonicatePlayer(){
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Social.Active.localUser.Authenticate(ProcessAuthentiation);
Debug.Log("Login Process ...");
}
// Call this method on Show Achievement Button action
public void GC_ReportAchievementScore(){
if(PlayerPrefs.GetInt ("Hero")> 0){
SubmitAchievementProgress("Achievement ID Here");
}
Social.ShowAchievementsUI();
}
void SubmitAchievementProgress(string MyID){
Social.ReportProgress(MyID, 100.0f, (bool success) => {
if(success){
print("successfully reported Achievement");
}else{
print("Something... wrong on report score");
}
} );
}
// Call this method on Show Leaderboard Button action
public void GC_ReportHighScore(){
long currentScore = PlayerPrefs.GetInt ("TotalScore");
Social.ReportScore(currentScore, "Your Leader Board ID", (bool success) => {
// handle success or failure
if(success){
print ("successfully reported");
}else{
print("Something... wrong on report score");
}
} );
((PlayGamesPlatform) Social.Active).ShowLeaderboardUI("Your Leader Board ID");
}
// Update is called once per frame
void Update () {
}
void ProcessAuthentiation(bool success)
{
if (success)
{
print("successfully authonicated");
}
else
{
print("fail to authonicate");
}
}
}
Hey ! thx for your idea :) but I have already done all those steps including the script. What I am looking for is a way to load/sync the user's highest score on Google leaderboard with the local score. The idea is to keep the score even when the user has uninstalled the app, that way when the user install it again, he/she will keep the highest score (not 0 again).
I am also thinking about cloud save state on that plugin, but I am stuck as well.
here is the current app btw : link text
Sorry bringing this up now. I am into the same situation now, couldn't find any solution. Please share if you have fixed this.
Answer by taxvi · Feb 19, 2015 at 11:08 AM
I'm having the same problem, unfortunately the plugin says this functionality is not supported yet :(
the same goes with plenty other functions like LoadFriends and LoadUsers, etc. Check the pop-up comments like in the pic before using the methods.
and yes, @meat5000 is right, writing your own plugin is much less pain (and makes you feel more powerful, muahahahaa...)
I am into the same situation now. Any one found a work around?
Nothing yet, the command is there but its not yet implemented, I dont know when it will be, I am just sing Android Native Plugin since its the only solution I know of so far.
Answer by wuym67123 · Jan 03, 2017 at 08:28 AM
public void loadTopLeaderboardScores(string leaderboardId, int span, int leaderboardCollection, int maxResults,bool forceReload)
Asynchronously load the top page of scores for a given leaderboard.
Your answer
Follow this Question
Related Questions
Google Play Games Plugin(A simple issue) 0 Answers
Cloud recognition in Vuforia 0 Answers
Google Play Services show leaderboard 1 Answer