question

radicalmonstergames@gmail.com avatar image
radicalmonstergames@gmail.com asked

UpdatePlayerStatistics doesnt give results.

Hey everybody,

I have a little problem with posting scores to the leaderboards (player statistics)

I gave players the permission to alter their statistics.
I have posted the script under this line but it wont give any results back.

public void UpdateGlobalScore(int score)
{
UpdatePlayerStatisticsRequest request = new UpdatePlayerStatisticsRequest()
{

Statistics = new List<StatisticUpdate>
{
new StatisticUpdate {StatisticName = "global" ,Value = score, Version = 0 }
}
};

PlayFabClientAPI.UpdatePlayerStatistics(request, (result) => { Debug.Log("Score Updated"); }, (error) => { Debug.Log("ERROR"); });
}

Can someone please tell me what i am doing wrong?

10 |1200

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

brendan avatar image
brendan answered

Thanks, I spoke with the tools team, and  they also found this bug yesterday and have a patch checked in for it. It's specific to Unity 5.3, and yes, that's the specific effect. The updated SDK with the fix for this will be in our next SDK release - early next week.

10 |1200

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

brendan avatar image
brendan answered

Can you try specifying the Statistics as an Array, rather than a List? The two types can't be implicitly converted to each other.

10 |1200

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

radicalmonstergames@gmail.com avatar image
radicalmonstergames@gmail.com answered

thnx for the answer.. but i found out what the problem was.
It was because of scene switching..

Playfab adds a object with a script on it. (PlayfabHTTP)
So that disapeared on scene switch.

My fix: Just add the script on a object that doesnt get removed on scene switch.

10 |1200

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

Amar avatar image
Amar answered

@Brendan

It looks like this problem still exist in the Unity 5.4 and the latest PlayFab SDK. I am using the latest UpdatePlayerStatistics, along with all List (Not array), as per the API requirement, and always getting the error.

Is this fixed or something wrong with my implementation?



    public void SubmitPlayerStats(int distance, int score)

    {

        if(!IsLoggedIn)

            return;



        List<StatisticUpdate> statList = new List<StatisticUpdate>();



        //DistStat

        StatisticUpdate distStat    = new StatisticUpdate();

        distStat.StatisticName      = Constants.LB_RecordDistance;

        distStat.Value              = distance;

        statList.Add(distStat);



        //ScoreStat

        StatisticUpdate scoreStat   = new StatisticUpdate();

        distStat.StatisticName      = Constants.LB_RecordSmashScore;

        distStat.Value              = score;

        statList.Add(scoreStat);



        UpdatePlayerStatisticsRequest request = new UpdatePlayerStatisticsRequest()

        {

            Statistics = statList

        };



        PlayFabClientAPI.UpdatePlayerStatistics(request,(result)=>

        {

            //Debug.Log(">>>>> 2 Sumbitting Player Stats >>>>>>");

            //Now that we have submitted the results get, the Leaderboard

            GetGlobalSmashScoreLB();



            if(FBMgr.EnabledForPlatform)

                GetFriendSmashScoreLB();



        },(PlayFabError error)=>

        {

            //Debug.Log(">>>>> 3 Sumbitting Player Stats >>>>>>");

            Debug.Log(error.GenerateErrorReport());



        });

    }

I tried sending this as an Array, instead of a List and seems like the ClientApI call does not want to take it.

10 |1200

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

brendan avatar image
brendan answered

First, what are the details of the error you get back from this call?

Next, a couple of points:

1. We highly recommend not turning on the permission to let clients call UpdatePlayerStatistics (which is off by default for all titles). Turning that on means that the client can submit stats, which makes it trivial for hackers to submit any scores they want to.

2. Querying a leaderboard immediately after submitting statistics is not a good idea, as it takes a non-zero amount of time for the leaderboard to update with the new score. It's likely that if you query the leaderboard in the success handler, you won't have the new score in it yet. The recommendation is to wait a second before querying the leaderboard.

10 |1200

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

Amar avatar image
Amar answered

@Brendan
Invalid input parameters
Statistics[1].StatisticName: The StatisticName field is required.
UnityEngine.Debug:Log(Object)
PFMgr:<SubmitPlayerStats>m__2F(PlayFabError) (at Assets/0_SmashWars/Scripts/PFMgr.cs:801)
PlayFab.Internal.<MakeApiCall>c__AnonStorey1B:<>m__69(String) (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:139)
PlayFab.Internal.<Post>c__Iterator6:MoveNext() (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:200)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Thats is the error I get, when I submit the stats to the server using the code above. Based on your recommendation, if we do not let the client to submit the score, how else would you submit the stats?

Do you recommend sending required parameters to the server, and server does the calculations for these stats, and updates the leader board?

Either way, a hacker would hack these parameters, that are sent to the server for the server to calculate the stats to be posted to leader board right?


10 |1200

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

brendan avatar image
brendan answered

What are the actual values of your two Constants in that call? The error code is stating that the second one is evaluating as either null or a zero-length string.

For your other questions:

The recommendation is to only write the stats in Cloud Script calls. The client then submits some information which you can then review, making any appropriate checks to see if that info is valid, such as if enough time has passed for a user to reasonably have finished a level (since his last report), whether the values reported are within the legitimate range for the level, etc.

And yes, a player who wants to cheat will send bad values to the Cloud Script. The difference is that if you let the client write to the statistic, there's absolutely nothing you can do to prevent bad values. If you use a Cloud Script, you can put in logic to evaluate what they've sent up and you can change that logic over time to adapt to what you see people doing, so that you can at least force them to update their hack (so that it can't just be copied and passed around to those without any technical knowledge).

10 |1200

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

Amar avatar image
Amar answered

I believe I found the issue, this is what happens when you drink too much or coffee. It looks like I am adding the second stat info to the first stat, and hence the second stats values are always empty.

-Thanks

10 |1200

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

Amar avatar image
Amar answered

Hi Brendan, I have moved my call to the ClouScript and it is working fine now. Just wanted to add that, there are two version of examples floating around the documentation for updating player stats using CloudScript.

The old/deprecated :UpdateUserStatistics

- This seems to be the example that sits in the basic examples that come with the default server (Or may be I had a version and you could not change the code in the non-default version I had)

- The new call : UpdatePlayerStatistics, is working for me now but had to waste a bunch of time before I figured out that I was using new payload, to old call. There is no way to figure out what is wrong in this case.

-A

10 |1200

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

brendan avatar image
brendan answered

The basic Cloud Script sample that's loaded into each title as Revision 1 is here, in our GitHub: https://github.com/PlayFab/CloudScriptSamples/tree/master/BasicSample. It was updated with UpdatePlayerStatistics back when we made that change, but we do not retroactively overwrite everyone's Revision 1 with that, to be safe. But you can always grab the latest version from our GitHub repo.

For the issue with UpdatePlayerStatistics, what specifically would have helped you to debug the issue and resolve it more quickly?

10 |1200

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

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.