question

KO JunYeoul avatar image
KO JunYeoul asked

Changing Title Data is not stable

*** Before Question, My native language is not English ***

I changed my TitleData's value through CloudScript.

Example of expect change(playerID/itemPrice/itemAmount)(itemAmount -3)

(before) TestID0/200/30,TestID1/100/16

(after) TestID0/200/27,TestID1/100/16

(Only changed that value)

After the change, I have get TitleData from CloudScript.

Against to expectations, data did not change or changed(It even changes into a totally different value).

Got the value not once, but every second, and the value didn't change or change for a while.

Example of result change(playerID/itemPrice/itemAmount)(itemAmount -3)

(before) TestID0/200/30,TestID1/100/16

(1st) TestID0/200/30,TestID1/100/16

(2nd) TestID0/200/27,TestID1/100/16

(3rd) TestID0/200/ 33 , TestID1/100/16(4th) TestID0/200/ 30 , TestID1/100/16 * * *

(Only changed that value)

I want the exact changed value immediately.

Is there a solution to stabilize the value?

And this is my CloudScript js code.

handlers.BuyTradeItem = function(args)
{
    var itemContainer = new Array();
    var itemStats = new Array();
    var index = parseInt(args.index);
    var amount = parseInt(args.amount);

    var result = server.GetTitleData(
        {
            Keys : [args.keyName]
        }
    );

    if(result)
    {
        var changedItemList = "";
        var itemList = result.Data[args.keyName];
        var cDataTemp = itemList.trim();
        
        itemContainer = itemList.split(',');

        itemStats = itemContainer[index].split('/');
        itemStats[2] = String(parseInt(itemStats[2]) - amount);
        itemContainer[index] = itemStats[0] + "/" + itemStats[1] + "/" + itemStats[2];

        for(var i = 0; i < itemContainer.length; i++)
        {
            if(i == 0)
            {
                changedItemList = itemContainer[i];
            }
            else
            {
                changedItemList = changedItemList + "," + itemContainer[i];
            }
        }

        var request = server.SetTitleData(
        {
            Key : args.keyName,
            Value : changedItemList
        });

        if(request)
        {
            return itemStats[2];
        }
    }
}
CloudScriptTitle Data
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

·
Seth Du avatar image
Seth Du answered

Title Data is not designed for frequently change as it is a sharded and cached resource which means it will take some time until all the endpoints become up-to-date.

May I ask what’s the scenario? If you are looking for frequently-changing public shared data resource, I believe you may need implement an external database or other external services. Please refer to: https://community.playfab.com/questions/12722/is-there-safe-read-from-titledata.html

2 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.

KO JunYeoul avatar image KO JunYeoul commented ·

I'm trying to make a trade market.

This is my scenario.

1. Save players' sales status in TitleData.

2. Other player get TitleData who want know sales status.

3. If another player makes a purchase, change the TitleData to match the purchase status.

Is there a storage method that can be read and written by many people other than TitleData?

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ KO JunYeoul commented ·

You don't have to save that in Title data. instead, Player Data is able to handle your requirement. Please refer to this thread:https://community.playfab.com/questions/30398/data-access-of-other-players.html.

Player self is able to update Player data while for those data that should only be modified by server, you can make use of Player Read-Only Data. For some data that is not visible to players, Player Internal Data is the best choice.

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]