how to pass my game Score to Game Center

Apr 26, 2012 at 8:17 PM

HI

i want to connect to Game Center with my game , i've done all coding i can see the game center open and works fine but when i pass my high score to game center in simulator it wont show the high score , not sure whats wrong :

 

 GKScore score = new GKScore("hsid") ;

 score.value = Highscore;

 Guide.showleaderboard() ; 

thanks for helping

Apr 27, 2012 at 4:00 AM

It won't show any scores until at least 2 different gamecenter accounts submit a score.  Same thing drove me nuts.  Create a 2nd account and try submitting.

Apr 28, 2012 at 12:06 AM

Thanks tschacht ,  work pretty well . 

Apr 29, 2012 at 12:30 AM

Hi,

I have created two accounts on GameCenter and I have submitted my scores, however, I don't' see any records. I am using the emulator. Here is my code:

 

			GKScore gkscore = new GKScore();
			gkscore.Value = 1000;

My app has a single leader board only, so there are no categories. My user is logged into the GameCenter before the game begins. Is my code correct?

Apr 29, 2012 at 12:52 AM

Here us the complete GC code that I use for saving scores:

 

When game starts, I attempt to sign the gamer in with:

 

Guide.IsVisible = true;
Guide.ShowSignIn(1, true);

 

Then, I call the following SaveScoreToIosGameCenter() function when I want to submit the scores:


		public static bool IsSignedIntoGameCenter() {
			if ( ( Gamer.SignedInGamers.Count > 0 ) && ( Gamer.SignedInGamers[0].IsSignedInToLive ) ) {
				return true;
			}
			return false;
		}
		
		public static SignedInGamer GetSignedInGamer() {
			if (IsSignedIntoGameCenter()) {
				return Gamer.SignedInGamers[0];
			}
			return null;
		}
		
		public static void SaveScoreToIosGameCenter(String category, long score) {
		
			if (IsSignedIntoGameCenter()) 
			{
					var gamer = GetSignedInGamer();
					if (gamer != null) {
						gamer.UpdateScore(category, score);
					}
			}
}



Apr 29, 2012 at 1:25 AM

Hi,

Thanks for the code and I really appreciate your help.

For my game, I created a single leader board. Its ID is com.jmawebtechnologies.spaceracermyleaderboard. Is that what I use for category? If not, do I leave category as an empty string? My leader board has no category, so that's why I'm asking.

Apr 29, 2012 at 12:52 PM

Hi

Did you setup leaderboard in "Manage Game Center" section in itunes connect ? 

 The “Leaderboard Reference Name” is an internal name that you must provide for each leaderboard. I Named mine “High Scores” . The “Leaderboard ID” is a unique alphanumeric identifier that you create for this leaderboard. I chose “hsid” .  i used this leaderboard ID later in GKScore to identity our leaderboard . 

GKScore score = new GKScore("hsid") ;

use below code to send the data to Game Center  :

score.ReportScore (delegate (NSError error)
			    {
				if (error != null)
				{		
				Console.WriteLine(error.LocalizedDescription);		
				}
				else
				{
				Console.WriteLine("Sent") ; 				
				}