question

tsuyoiraion avatar image
tsuyoiraion asked

Store values for specific dates (i.e 10-01-18, 11:34pm, 22 Minutes \ holds various values from game (i.e Level 1 - Resistance)

Hello,

So the basic idea is to store and receive player values that are based on the date the player played the game, for example:

10-01-18

This would hold the date, time it was played at and the length of time played.

I would most likely grab the date and time from the actual stored playfab stat data and then custom store the length of time played.


The important factor is to grab the date played as that will be the initial factor when putting the data in a list to display in game.

Linked to the date will be other various stats such as:

Resistance

Hits

Misses

Etc.

Each of the values above will have 5 values for the 5 levels in the game.

So the question is how do i do something like this properly? Both getting and saving the stats.

Player Datadata
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.

tsuyoiraion avatar image tsuyoiraion commented ·

I'm currently using this method for an initial test, i don't mind manually setting it as it's not a competitive game and will be solely used on commercial environments.

    public void SetValues(){
        
            PlayFabClientAPI.UpdatePlayerStatistics( new UpdatePlayerStatisticsRequest {
                
                // request.Statistics is a list, so multiple StatisticUpdate objects can be defined if required.
                Statistics = new List<StatisticUpdate> {
                new StatisticUpdate { 
                    
                    StatisticName = "strength", 
                    
                    Value = 21 
                
                },
            }
        },
                result => { Debug.Log("User statistics updated"); },
                error => { Debug.LogError(error.GenerateErrorReport()); });
    }
0 Likes 0 ·
JayZuo avatar image
JayZuo answered

I'm not sure what your question is. Do you want to know how to update player statistics? Your code seems right, if you have allowed client to post player statistics in API Features then it should be able to work.

28 comments
10 |1200

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

tsuyoiraion avatar image tsuyoiraion commented ·

We'll as indicated above i'm looking to update and get the statistics via runtime, so the sample code is just an copy of the api from the playfab website but doesn't actually cover what i mentioned above and the way to store the information the way i need.

I think I was pretty clear above but if not I can go into more detail.

0 Likes 0 ·
brendan avatar image brendan tsuyoiraion commented ·

The problem is that you've described a specific implementation (you want to save some data, including a date and some statistics), but your use case isn't really clear. For example, the simplest answer would be to store all that together as a JSON blob in player or entity data, since it sounds like you want to have all the data together. But if you're trying to use the statistics in a leaderboard, you would literally want them to be statistics in PlayFab, using the API call you called out above. But statistics are stored individually, so you wouldn't be storing them as a unit, with your timestamp.

Having a high-level picture of the actual gameplay you're trying to implement, along with any requirements you have, is usually the best place to start from. If you can provide us with that, I'm sure a member of the team can advise you on the recommended path to take.

1 Like 1 ·
tsuyoiraion avatar image tsuyoiraion brendan commented ·

Yup this is what I thought, storing the stats in a leaderboard as individual statistics doesn't seem like the right way to go, so I figured I should ask the proper way for my setup.

I did think of a JSON but i do need to have the stats stored in playfab online, on scene start i'll store the player data and then set it in the proper areas via runtime.

Here's a few image examples of what I want to accomplish.

This area will instantiate intractable prefabs that holds the date, time and length of gameplay, so what i would do is check dates and then instantiate each date collected.

This area will populate the data stored for each date (i.e hits, misses, etc.) based on the date selected, so you can click on the date prefab then it will open the actual stats page.

0 Likes 0 ·
test1.jpg (143.0 KiB)
test2.jpg (140.7 KiB)
Show more comments
Show more comments
tsuyoiraion avatar image
tsuyoiraion answered

Alright so I was able to get serialization working and the playerdata updates correctly, here's the method:

So what i did was created a class for the data to be serialized:

public class DataTest {


    public string time;
    public string duration;
    public string resistance;


}

And then i grab/set values, serialize it, return the values and assign them in the player data update:

    public void SerialObj(){
        
        DataTest myData = new DataTest();
        myData.duration = "2 Min.";
        myData.resistance = "10";
        
        myData.time = System.DateTime.Now.ToString("hh:mm:ss");
        
        testString = PlayFabSimpleJson.SerializeObject(myData);
        
        SetValues();
    }
    
    
    public void SetValues(){
        
        PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest() {
            
            Data = new Dictionary<string, string>() {
            {date, testString}
                
        }
    }, 
    
        result => Debug.Log("Successfully updated user data"),
        error => {
        Debug.Log("Got error setting user data Ancestor to Arthur");
        Debug.Log(error.GenerateErrorReport());
        
        });
    }

The actual result testString shows is:


{"time":"10:39:11","duration":"2 Min.","resistance":"10"}

So since date is saved separately or in a different class it's not included in the serialization, so i can use it as the keys name and then the testString for the value of the player data string/string update


playdata.jpg (201.0 KiB)
18 comments
10 |1200

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

tsuyoiraion avatar image tsuyoiraion commented ·

@Brendan so now that serialization and saving the string is working, the question is, deserialization and then separating the values. Obviously i'd use the PlayFabSimpleJson.DeserializeObject(myData) call but how would I separate the string into the necessary pieces?

Also, since the name is being saved as a date, what's the proper way to get all the values saved there? Considering i wouldn't be calling specific names (i.e Ancestor, etc.), id be searching for all the values saved there (i.e 3-2-19, 5-2-19, etc.) and then loading those.

0 Likes 0 ·
brendan avatar image brendan tsuyoiraion commented ·

How many total Keys are you planning on saving? By using the date as the key, that could result in a growing list of data keys, which could eventually start to cause you performance issues (say you keep adding and wind up with a hundred keys or more, for example).

For deserialization, have a look at this thread - in specific, how they handle the return from the Cloud Script: https://community.playfab.com/questions/24184/json-serialization-and-deserialization-optimizatio.html. In short, you don't separate the pieces - you deserialize the object from it's JSON stringified version into an object of the same type.

1 Like 1 ·
tsuyoiraion avatar image tsuyoiraion brendan commented ·

@Brendan Deserialization - Gotcha, i'll look into that in a bit.

Key saving - There actually won't be a limit on how many dates can be saved as this will be used for hospital use and each dates values, etc. will be comparable in a core application that checks how much the patient progresses over time.

What sort of performance impact do you mean? Instantiation of the dates or actually getting the values from playfab?

0 Likes 0 ·
Show more comments
Show more comments

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.