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

LeaderboardResultToEntries return null not zero size Array #791

Open
ZhangHuan0407 opened this issue Nov 30, 2024 · 0 comments
Open

LeaderboardResultToEntries return null not zero size Array #791

ZhangHuan0407 opened this issue Nov 30, 2024 · 0 comments

Comments

@ZhangHuan0407
Copy link

Is your feature request related to a problem? Please describe.

  • When I was using leaderboard.GetScoresForUsersAsync(SteamId[]), I noticed that if all your friends aren't on the leaderboard, null would be returned.
  • If the network connection is interrupted and the leaderboard data cannot be obtained, null is returned.
  • This return value confuses me, because I can't speculate from the return value data whether the current prompt for "network error" should be displayed, or if all of my friends don't have a score.
// Leaderboard
    public async Task<LeaderboardEntry[]> GetScoresForUsersAsync(SteamId[] users)
    {
        if (users == null || users.Length == 0)
        {
            return null;
        }

        LeaderboardScoresDownloaded_t? leaderboardScoresDownloaded_t = await SteamUserStats.Internal.DownloadLeaderboardEntriesForUsers(Id, users, users.Length);
        // !!!!!!!!!!!!!!!! I'm guessing it could be return null, when the network connection drops?
        if (!leaderboardScoresDownloaded_t.HasValue)
        {
            return null;
        }

        return await LeaderboardResultToEntries(leaderboardScoresDownloaded_t.Value);
    }

    internal async Task<LeaderboardEntry[]> LeaderboardResultToEntries(LeaderboardScoresDownloaded_t r)
    {
        //!!!!!!!!!!!!!!!! I'm guessing it's this branch, but I didn't add logs to debug
        if (r.CEntryCount <= 0)
        {
            return null;
        }

        LeaderboardEntry[] output = new LeaderboardEntry[r.CEntryCount];
        LeaderboardEntry_t pLeaderboardEntry = default(LeaderboardEntry_t);
        for (int i = 0; i < output.Length; i++)
        {
            if (SteamUserStats.Internal.GetDownloadedLeaderboardEntry(r.SteamLeaderboardEntries, i, ref pLeaderboardEntry, detailsBuffer, detailsBuffer.Length))
            {
                output[i] = LeaderboardEntry.From(pLeaderboardEntry, detailsBuffer);
            }
        }

        await WaitForUserNames(output);
        return output;
    }

Describe the solution you'd like

  • Try to distinguish between leaderboard data fetch failed and all of my friends aren't on the leaderboard.

Describe alternatives you've considered

  • Solution 1: leaderboard.GetScoresForUsersAsync leaderboard.GetScoresAsync
  • Add a parameter to tell me that the leaderboard data is fetched failed when it is executed (e.g. StatusCode.NoData and LeaderboardEntry[] are null),
  • or if the leaderboard data is returned normally but the length is zero (e.g. StatusCode.HaveData and LeaderboardEntry[] are null)
  • Solution 2: If leaderboard data is returned normally, but when the length is zero, Array.Empty() is returned.

Additional context

  • This is the first time I used the steam leaderboard feature, I may have misunderstood with the framework.
  • If the current version has a callback or parameter that can distinguish between the two cases, it would be appreciated.
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

No branches or pull requests

1 participant