question

vipulchandu123 avatar image
vipulchandu123 asked

can anyone help me out to get away from the problem that occured in the coding part of using prize table in leaderboards in playfab documentation

Leaderboards and Statistics
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

We have tested this code sample in our testing project. It works fine. Sometimes, when people mess up the brackets or miss the semicolons, this error message would appear, please further check your code. Here is the full code of my testing script.

using PlayFab;
using PlayFab.ClientModels;
using System.Collections.Generic;
using UnityEngine;


public class PlayFabTouramentPrizeManual : MonoBehaviour
{
    void Start()
    {
        CreatePlayerAndPopulateLeaderboard();
    }


    public void CreatePlayerAndPopulateLeaderboard(int playerIndex = 5)
    {
        if (playerIndex <= 0) return;
        const string leaderboardName = "tournamentScore_manual";
        PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest
        {
            CustomId = playerIndex.ToString(),
            CreateAccount = true
        }, result => OnLoggedIn(result, playerIndex, leaderboardName), FailureCallback);
    }


    private void OnLoggedIn(LoginResult loginResult, int playerIndex, string leaderboardName)
    {
        Debug.Log("Player has successfully logged in with " + loginResult.PlayFabId);
        PlayFabClientAPI.UpdatePlayerStatistics(new UpdatePlayerStatisticsRequest
        {
            Statistics = new List<StatisticUpdate> {
            new StatisticUpdate {
                StatisticName = leaderboardName,
                Value = playerIndex + 100
            }
        }
        }, result => OnStatisticsUpdated(result, playerIndex), FailureCallback);
    }


    private void OnStatisticsUpdated(UpdatePlayerStatisticsResult updateResult, int playerIndex)
    {
        Debug.Log("Successfully updated player statistic");
        // Recursively invoke for next player
        CreatePlayerAndPopulateLeaderboard(playerIndex - 1);
    }


    private void FailureCallback(PlayFabError error)
    {
        Debug.LogWarning("Something went wrong with your API call. Here's some debug information:");
        Debug.LogError(error.GenerateErrorReport());
    }
}


1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

vipulchandu123 avatar image vipulchandu123 commented ·

thank you dear

\

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.