2

I signed up for the Xbox Creators Program, and I'm trying to get a leaderboard. However I couldn't find any examples that use the C# API. This page shows how to do it in C++.

Here is my code. It won't build because it says XboxLiveContext doesn't have a LeaderboardService property. How do I create a leaderboardservice in C#?

XboxLiveUser user = new XboxLiveUser();

SignInResult x = await user.SignInAsync();

XboxLiveContext context = new XboxLiveContext(user);

LeaderboardResult result = await context.LeaderboardService.GetLeaderboardAsync("scores1", new LeaderboardQuery());
Timothy G.
  • 6,335
  • 7
  • 30
  • 46
nbarkhina
  • 45
  • 3

1 Answers1

2

For C# Xbox Creators Program some of the APIs have been moved around. The Leaderboards APIs are now part of the StatsManager. You can use StatsManager.Singleton.GetLeaderboard(...) make a request to get a leaderboard.

That starts the request in the background, and when it's complete, an event will be returned by a call to StatsManager.Singleton.DoWork(). The DoWork method is intended to be called every frame (or whenever you want to be notified of events from StatsManager). Take a look at the Xbox Live Unity Plugin Leaderboards implementation for an example of how to do this.

Ben Randall
  • 1,205
  • 10
  • 27
  • 1
    Thanks Ben. This is helpful. Now I am having an issue with the StatsManager in general. The other API's work for me, XBoxUser, SocialManager etc... but StatsManager is crashing on StatsManager.Singleton.AddLocalUser(user). Could it be I didn't set up stats correctly? according to this link I have to first set up my stats. https://developer.microsoft.com/en-us/games/xbox/docs/xboxlive/data-platform/player-stats/player-stats however I don't have this link in my Dashboard. I only have the Xbox Live link under services. How do I create my Stats, is this a limitation of Creators Program Users? – nbarkhina Mar 14 '17 at 22:11
  • StatsManager should be working properly, however if you have separate questions can you mark this answer as final and submit a new question with any additional error detail you might be seeing? – Ben Randall Mar 17 '17 at 07:12
  • @nbarkhina Did you get leaderboards working with C#. I've tried and it errors/throws and exception when just accessing the EventArgs that contains the leaderboards. Even though the ErrorCode is 0?!? If you have any ideas, I'd love to pick your brain. – Dominique Mar 27 '21 at 18:24
  • Yes I did get it to work. Though the leaderboard apis don't do much. I use them though the statistics don't seem to be accessible from anywhere, but if you're interested I can help you get it going. – nbarkhina Mar 28 '21 at 19:09