Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

GameCenter Plugin Live! Leaderboards and Achievements!

Discussion in 'iOS and tvOS' started by prime31, Sep 6, 2010.

  1. bitever

    bitever

    Joined:
    Mar 4, 2012
    Posts:
    17
    @Prime31 thanks again. I checked the data and are passed correctly, I thing the problem is that event doesn't fire when I change the match with my button (event for method currentMatchChanged), then I can use the object GKTurnBasedMatch.

    When I do through MatchmakerViewController, xCode gives me the following log:

    Code (csharp):
    1. 2012-03-28 19:09:38.534 pruebaMulti[4245:707] checking for match. requested match: 702f3509-befe-4dd7-8505-ae82f98f1b48, compared to stored match: 702f3509-befe-4dd7-8505-ae82f98f1b48
    2.  
    3. loaded match: 702f3509-befe-4dd7-8505-ae82f98f1b48. The match data will be automatically fetchd for us.
    And when I do it through my button:

    Code (csharp):
    1. 2012-03-28 19:09:05.490 pruebaMulti[4245:707] checking for match. requested match: 702f3509-befe-4dd7-8505-ae82f98f1b48, compared to stored match: 702f3509-befe-4dd7-8505-ae82f98f1b48
    I'm using your example method to change the match:

    Code (csharp):
    1. private void currentMatchChanged( GKTurnBasedMatch match )
    2. {
    3.     // probably not the most user friendly thing to do but we will just swap to whatever match just had an event
    4.     _currentMatch = match;
    5.     GameCenterTurnBasedBinding.changeCurrentMatch( match.matchId );
    6.     Debug.Log( "loaded match: " + match.matchId + ". The match data will be automatically fetched for us." );
    7. }
     
  2. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    Hi Prime,

    I did a new build from Unity to Xcode (replace, not append) and now I get these error messages.
    I even tried to delete the Gamecenter plugin from my project and import again using the .unitypackage

    Any idea how to relink your plugin with Xcode?
    Thanks.

     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Bit, it seems to work fine for me using the demo scene. Have you tried using it directly while testing? Did you finish the current players turn in some fashion before changing to the other match?


    @laser, update your plugin. A new version was released when Xcode 4.3 dropped with support for the new tools.
     
  4. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    Awesome, thanks for the ultrafast reply :)
     
  5. wheats

    wheats

    Joined:
    Aug 3, 2011
    Posts:
    14
    Hi @Prime I am having some trouble posting achievements. I am coding in javascript and I don't quite know how to re-write this C# code:

    Because I need to use the following code which relies on the above code as reference.

    Love the Plugin BTW.

    Thanks in Advance

    Wheats
     
  6. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @wheats, if you plan on using generics in JS I would recommend having a look through some of the past posts on the subject here.

    As for the event syntax it is identical between JS/C#. Have a look at the *EventListener.cs file for examples. Both C# and JS use the same "+=" operator to add an event listener and "-=" to remove it.
     
  7. wheats

    wheats

    Joined:
    Aug 3, 2011
    Posts:
    14
    Thanks for such a quick reply. A quick look at the link you posted showed me how to restructure in JS. Everything else has been fine just could get my head around this part "List<GameCenterLeaderboard>" because I have never used Lists like this.

    Thanks Again
     
  8. wheats

    wheats

    Joined:
    Aug 3, 2011
    Posts:
    14
    Hi I have had a crack at writing it in JS but I just can't seem to get the syntax right. Could please help in writing the following code in JS.

    Sorry to be a pain...

    private List<GameCenterLeaderboard> leaderboards;
    private List<GameCenterAchievementMetadata> achievementMetadata;


    GameCenterManager.categoriesLoaded += delegate( List<GameCenterLeaderboard> leaderboards )
    {
    this.leaderboards = leaderboards;
    };

    GameCenterManager.achievementMetadataLoaded += delegate( List<GameCenterAchievementMetadata> achievementMetadata )
    {
    this.achievementMetadata = achievementMetadata;
    };

    Thanks in advance
     
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @wheats, I personally do not use JS due to its syntax oddities, missing features and lack of solid IDE support. You may want to post in the scripting section of the forum so some JS pros can let you know what the proper syntax is.
     
  10. bitever

    bitever

    Joined:
    Mar 4, 2012
    Posts:
    17
    @prime31, Finally I restarted the project, download the latest versions of the plugins, and used the same code and it worked.

    Sorry for the inconvenience and thanks for the help.
     
  11. Hungariano

    Hungariano

    Joined:
    Mar 24, 2009
    Posts:
    60
    Hi.
    I have a question about leaderboards and achievements. maybe the answer is easy but I can´t seem to find it.

    Are leaderboards and achievements unique for a game, or unique for each game version?

    We have a go-kart game and sometimes we make changes to the kart which makes the lap times change.
    That means that earlier when we released a versions where the difference was to big we reset all lap times and cleared our website
    where we had our leaderboards.

    Now I am integrating GameCenter instead but I am stuck on how to handle this kind of stuff in the future.

    If the leaderboards are unique for each game version, there is no problem.

    Appreciate all input/help on this:)
     
  12. Deleted User

    Deleted User

    Guest

    Hungariano, app updates by default use the same leaderboards as the previous version, but you can specify any or none, and you can add new ones.
     
  13. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @hungar, I believe leaderboards are global but you will definitely want to check Apples documentation for a definitive answer
     
  14. Hungariano

    Hungariano

    Joined:
    Mar 24, 2009
    Posts:
    60
    Thanks for the answers guys!

    @prime I know there is a method to reset achievements but would it be possible to reset leaderboards too in some way?

    Best would be if I could clear them totally. I have to read the Apple docs again:)
     
  15. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,571
    Why not set up a new leaderboard and have your code take them to that one? That way players don't lose the high scores they spent time getting.
     
  16. Hungariano

    Hungariano

    Joined:
    Mar 24, 2009
    Posts:
    60
    @Prime
    Where is the correct place to put GameCenterBinding.showCompletionBannerForAchievements?

    Should I put it in GameCenterBinding.reportAchievement or in the reportAchievementFinished event?

    /Peter
     
  17. BogdanDude

    BogdanDude

    Joined:
    Jun 18, 2009
    Posts:
    89
    hey @prime31!

    I just found a nasty bug in your Game Center Multiplayer code and fixed it for you.
    This is the good version:

    - (void)showMatchmakerWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers
    playerGroup:(NSUInteger)playerGroup playerAttributes:(uint32_t)playerAttributes
    {
    [self showMatchmakerWithMinPlayers:minPlayers maxPlayers:maxPlayers playerGroup:playerGroup playerAttributes:playerAttributes playersToInvite:nil];
    }

    and this is your version:

    - (void)showMatchmakerWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers
    playerGroup:(NSUInteger)playerGroup playerAttributes:(uint32_t)playerAttributes
    {
    [self showMatchmakerWithMinPlayers:minPlayers maxPlayers:maxPlayers playerGroup:0 playerAttributes:0 playersToInvite:nil];
    }

    This was in GameCenterMultiplayer.mm (and we weren't able to start separate Game Center matches for Versus and CO-OP, as the players would mix between those 2 modes)
     
  18. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Hungariano, you can put that call anywhere, even at app launch.


    @Bogdan, good spot! Just fixed it and will push out an update shortly.
     
  19. Hungariano

    Hungariano

    Joined:
    Mar 24, 2009
    Posts:
    60
    @Prime Thanks, I put it in the Start() method and it works like a charm.
     
  20. Hungariano

    Hungariano

    Joined:
    Mar 24, 2009
    Posts:
    60
    Hi guys.
    Does anybody else having issues with the sandbox leaderboards?

    They seem extremely slow and unresponsive. Yesterday I could upload lap times just fine, even though it took some time before they showed up. In the evening I went and deleted the test data through iTunes Connect and after that no submissions are showing up.

    I get the callback that submission was successful and everything but nothing shows up. Really annoying and time consuming.

    Does anybody have any thoughts about this, or if I am missing something.

    /Peter
     
  21. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,571
    Yes, the sandbox is often slow and unresponsive. Has been that way since I first used it 18 months ago. I have read that if something is not showing up, a possible solution is to log out of Game Center and then log in with another ID.
     
  22. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    266
    I have a question regarding syncing achievement data. We're storing all the achievement data locally, and then when the player logs into GameCenter, I'm reporting the data to GameCenter to keep things in sync (say, if GameCenter isn't available for awhile). The first problem with that, is that any achievements at 100% fire off the Completion Banner every time the player logs in - is it supposed to be the case that reporting an achievement at 100% multiple times causes multiple Completion Banners?

    To remedy this, I tried to first get the achievement data from GameCenter using getAchievements(). However, when a add an event handler, it always seems to be called twice - once with a list of 0, and then a second time with the full list of achievements. Is that callback supposed to operate that way?
     
  23. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @krom, anytime you report an achievement as 100% Apple shows the banner. As for achievements being loaded with an empty list I can't seem to reproduce that. Apple always seems to load up the proper data in my tests. Make sure the player is authenticated when you fire off the request to get the achievements.
     
  24. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    266
    Hi, thanks for getting back so quickly. It seems that the achievementsLoaded callback is being called when I authenticate as well as when I call getAchievements. For some reason, when I called getAchievements in the callback for player authentication, that was causing some weird behavior.

    For example, I had a problem doing this:
    Code (csharp):
    1.  
    2. GameCenterManager.playerAuthenticated += GameCenter_Event_PlayerAuthenticated;
    3. GameCenterBinding.authenticatePlayer();
    4.  
    5. GameCenter_Event_PlayerAuthenticated() {
    6.     GameCenterManager.achievementsLoaded += GameCenter_Event_AchievementsLoaded;
    7.     GameCenterBinding.getAchievements();
    8. }
    9.  
    but this worked fine:
    Code (csharp):
    1.  
    2. GameCenterManager.playerAuthenticated += GameCenter_Event_PlayerAuthenticated;
    3. GameCenterManager.achievementsLoaded += GameCenter_Event_AchievementsLoaded;
    4. GameCenterBinding.authenticatePlayer();
    5.  
    Should player authentication be also causing the achievementsLoaded event to fire? It seems like an unexpected side effect of authenticating the player. It seemed that calling getAchievements() when the callback was already happening was the cause of the weird list of achievements being returned.
     
  25. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @krom, achievements are always auto loaded. It is a requirement for some of the other methods in the plugin.
     
  26. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    I am having this weird issue with LIVE gamecenter, which works fine in sandbox mode.

    When I get authenticated i run:
    Code (csharp):
    1. void playerAuthenticated()
    2.     {
    3.         Debug.Log( "playerAuthenticated" );
    4.         GameCenterBinding.retrieveScoresForPlayerId(GameCenterBinding.playerIdentifier());
    5. }
    Which is executed fine. GameCenterBinding.playerIdentifier() returns my playerid.

    Then this triggers:
    Code (csharp):
    1.  
    2.     void scoresForPlayerIdLoaded( List<GameCenterScore> scores )
    3.     {
    4.         Debug.Log( "scoresForPlayerIdLoaded" );
    5.         foreach( GameCenterScore s in scores )
    6.             Debug.Log( s );
    7. }
    8.  
    But "scores" does not contain anything! the Debug.Log( s ) does not print anything at all on the live server.
    I currently have 6 players with successfully reported scores in gamecenter. I´m able to view them when i manually open the official gamecenter leaderboards.

    My game was released today at the AppStore. Is this some kind of bug from Apples side? Will it solve itself in time?

    Thanks for all replies, this is urgent! :<
     
  27. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @laser, there isn't much I can tell you about the situation besides to open a bug report with Apple. There is no way for us to see what is actually happening under the covers on those method calls to load the scores.
     
  28. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    Guess it was just a delaythingy.. Its 14 hours since release, and I´ve been kinda frustrated this whole time.

    And now, 10 seconds before I send in a bugreport, it fixes itself :p
    Thanks anyway Prime:)
     
  29. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    @Prime31

    I've uploaded an update of my game to iTunesConnect. The update status is 'waiting for review'. On the metadata page in iTunesConnect it states : 'no new leaderboards have been set up' and the leaderboard for the original version does not appear. Do I need to set up a new leaderboard for each update? I've noticed since building the update that hi-scores are no longer being posted to the sandbox leaderboard. The game is due for release as soon as the update is approved.
     
  30. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @recluse, you only need to add leaderboards once and once your app is released they can no longer be modified.
     
  31. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    ha those damn speechmarks, was trying everything i could possibly try for over an hour then saw this comment which made me try the speech marks and it worked XD bahh
     
  32. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    @Prime31, that's what I want to hear. Just wondering why scores are not being reported in my updated version - is it because it is waiting for review? None of the metadata is editable either on iTunesConnect.
     
  33. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @recluse, you will have to contact Apple to get that kind of information. We have no way of knowing what is going on with their servers.
     
  34. Hungariano

    Hungariano

    Joined:
    Mar 24, 2009
    Posts:
    60
    @recluse Just a thought here. Maybe you have done this already but anyways:)

    You just have to add leaderboards and Achievements once per game. But make sure that you select which of each you want to include in each version of the game.

    This is done in the Meta information for each version. Hope you understand what I mean:)
     
  35. Recluse

    Recluse

    Joined:
    May 16, 2010
    Posts:
    485
    @Hungariano I already did all that and it all worked perfectly the first time, but the update doesn't allow me to edit anything - perhaps because its waiting for review? I realize I should check with Apple, but thought someone here might have experienced the same thing - their leaderboard not working when a game has been updated, but not yet approved. I'll get on to the big A...
     
  36. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    is there a way to keep adding an Achievement Percentage, as:
    GameCenterBinding.reportAchievement( "100ddrinks", 1 );
    just sets the achievement to 1% every time

    I'm looking for one where it increases it every trigger touch for example, rather than setting it to 1% every trigger touch

    eg.
    1% + 1% = 2% (want it to do)
    1% + 1% = 1% (currently does)
     
  37. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jesus, either store the current percentage locally when you set it or alternatively you can send off a request to get the achievements from GameCenter with getAchievements and use those values as your current base.
     
  38. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    i see i have an idea of one way of doing it, just wondered if there was a simpler one line code way, maybe something to add in a future update? :p thanks.
     
  39. g.e

    g.e

    Joined:
    Jun 9, 2011
    Posts:
    17
    I think I'm having a similar problem to Hungariano's here.

    I've got Game Center setup through iTunes connect with a bunch of leader boards for the current version. I then do everything according to the doc on prime31's website: log out through the Game Center app, launch the game, log in to my Game Center sandbox account through the game and get the Welcome back message.
    I then play and report a score at the end of the game and get the "reportScoreFinished" event fired correctly. But then nothing shows up on the actual leader board when I launch it through the game.
    I have tried many things: logging out and back in; creating another sandbox account which I also added as a friend on my first one, etc. The leader board still remains empty...

    Does anyone have an explanation, fix or workaround for this? Or is it just because of the sandbox being extremely slow? (The first time I reported scores was two days ago and there's still nothing)
     
  40. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @g.e., if you check back in this thread you will see delayed scores discussed all the time. There is nothing you can do about it. As long as the reportScoreFinished event is firing your code is working properly. The sandbox servers are just horrendously slow sometimes. Don't forgot to file a bug report with Apple so they hear it loud and clear!
     
  41. g.e

    g.e

    Joined:
    Jun 9, 2011
    Posts:
    17
    Thanks a lot for the speedy response :)
    I did see this problem occurring a few times, good to hear I wasn't doing anything wrong - it's just really annoying to have to test blindly.
     
  42. Daxter12

    Daxter12

    Joined:
    Oct 9, 2011
    Posts:
    8
    Hi There,

    I purchased the gamecenter plugin today. I'm currently posting my score to gamecenter, but when I check the leaderboard it shows "No Score"

    I have submitted using two devices as well.

    The code I've to submit is as follows:

    CurrentScore is an integer that holds the games current score.

    The XCode Log returns: "reportScoreFinished for category: OnslaughtMode" - OnslaughtMode being the ID for my leaderboard.
     
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @daxter, check back in this thread for more info. This topic comes up every few days. It is entirely normal in the sandbox.
     
  44. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    I´m implementing achievements in my game. All of them are either 0% or 100% achieved, say when you score 10.000 points in one run (endless runner).
    Is there any harm in reporting the 10.000point-achievement _every time_ the player aquire that score? Or should I do an interntal check and see if is has been sent before?

    Thanks.
     
  45. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @laserlars, give it a try and see if it causes issues. The only thing I can think of would be if you are showing the achievement banner and it gets shown each time
     
  46. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    Great. I went with the internal check first, so the banner won't show each time. This could cause some trouble if the player uses more than 1 gamecenter account, but that's a fight for another day. Thanks.
     
  47. GameFreak

    GameFreak

    Joined:
    Oct 31, 2011
    Posts:
    13
    Prime31,

    I am using iOS 5 and uhh Unity 3.4

    I built a game with GameCenter and got 32 Apple Match O linkers


    Undefined symbols for architecture armv7:
    "__gameCenterResetAchievements", referenced from:
    __Z19RegisterMonoModulesv in RegisterMonoModules.o
    "__gameCenterIsGameCenterAvailable", referenced from:
    __Z19RegisterMonoModulesv in RegisterMonoModules.o
    "__gameCenterAuthenticateLocalPlayer", referenced from:
    __Z19RegisterMonoModulesv in RegisterMonoModules.o
    "__gameCenterRetrieveScores", referenced from:
    __Z19RegisterMonoModulesv in RegisterMonoModules.o
    "__gameCenterShowCompletionBannerForAchievements", referenced from:
    __Z19RegisterMonoModulesv in RegisterMonoModules.o

    And More

    I havent set up the Game in game center yet however it should open on the phone and say gamecenter doesnt recognize this game right?

    Whats going wrong?
     
  48. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @GameFreak, it appears the post process scripts did not run. First of all, make sure you have the latest version of the plugin. Do a Build followed by Replace to get a fresh Xcode project ensuring Xcode is completely shut down when doing this. If you do not see a Finder popup letting you know the scripts ran successfully consult the last paragraphs of the General section of the documentation for how to get logs to send us.
     
  49. LeshaVH

    LeshaVH

    Joined:
    Mar 22, 2010
    Posts:
    84
    Prime, how to make game center and leaderboard autorotation when device is rotated?
     
  50. LionTR

    LionTR

    Joined:
    Mar 26, 2010
    Posts:
    33
    Hi Prime!

    I have a quick question on "retrieveScores". What do the start and end parameters mean exactly? Since you wrote they have to be between 1 and 100 I guess they are percentages of the full scoreboard? Or can I only call for the first 100 scores?
     
    Last edited: May 23, 2012