Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • Bugs /
avatar image
Question by Jacob van der Vliet · Jun 06, 2019 at 06:23 AM · CloudScriptdata

Why does UpdateUserInventoryItemCustomData add all of it's field to item custom data??

In cloudscript I am trying to fill in an items custom data with the custom data from the catalog item.

When I run the server.UpdateUserInventoryItemCustomData from cloud script it adds the PlayFabId, ItemInstanceId and Data field as individual entries in the custom data, and does not work if those fields are not there? Is this intended behavior? It seems wonky.

Result: https://i.imgur.com/8eYS5vH.png

Cloudscript:

server.UpdateUserInventoryItemCustomData({
                PlayFabId: currentPlayerId,
                ItemInstanceId: instanceId,
                Data: item.CustomData
            });

Comment

People who like this

0 Show 1
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jacob van der Vliet · Jun 06, 2019 at 06:52 AM 0
Share

This is the full function for context. It is called with the player_inventory_item_added rule.

handlers.newItemAdded = function(args, context) {
    let response = server.GetCatalogItems({
        CatalogVersion: "Main"
    });

    let catalog = response["Catalog"];

    let eventData = context.playStreamEvent;
    let addedId = eventData.ItemId;
    let instanceId = eventData.InstanceId;

    for (let itmIdx in catalog) {
        let item = catalog[itmIdx];

        if (item.ItemId == addedId && item.CustomData) {

            log.debug("Custom Item Data: " + item.CustomData);

            var req = {
                PlayFabId: currentPlayerId,
                ItemInstanceId: instanceId,
                Data: item.CustomData
            };
            server.UpdateUserInventoryItemCustomData(req);

            return;
        }
    }
};

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Jacob van der Vliet · Jun 06, 2019 at 12:22 PM

Well I feel silly, the item.CustomData was a string not a json object!

This is still some very strange behavior! I would expect this to throw the "data must contain at least one key/value" error, not insert my PlayFabId and ItemInstanceId as well as data.

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by SethDu · Jun 06, 2019 at 08:19 AM

It is not the intended behavior, the problem can be the format of your json variable “item” is incorrect. I have written a hard-coded test example, please see the difference in your code:

handlers.test =
  function (context) {
    var item ={ 
      "name":"testitem", 
      "CustomData": { 
        "AttackSpeed":1, 
        "Damage": 40 
      }
  };

  server.UpdateUserInventoryItemCustomData({
    PlayFabId: "xxxxxxxxx",
    ItemInstanceId: "xxxxxxxx",
    Data: item.CustomData
    }
  );
}

The test result is:

In addition, from your code:

handlers.newItemAdded = function(args, context) {
    let response = server.GetCatalogItems({
        CatalogVersion: "Main"
    });

    let catalog = response["Catalog"];

    let eventData = context.playStreamEvent;
    let addedId = eventData.ItemId;
    let instanceId = eventData.InstanceId;

    for (let itmIdx in catalog) {
        let item = catalog[itmIdx];

        if (item.ItemId == addedId && item.CustomData) {

            log.debug("Custom Item Data: " + item.CustomData);


	    // Please see the changes below:


            var req = {
                PlayFabId: currentPlayerId,
                ItemInstanceId: instanceId,
                Data: JSON.parse(item.CustomData)
            };
            server.UpdateUserInventoryItemCustomData(req);

            return;
        }
    }
};

The CustomData retrieved from other callbacks should be a string, you need to parse it into an Object before you use it.

Be aware that please enable "Publish results as PlayStream Event", so that you can see the result in the PlayStream monitor.


snipaste-2019-06-06-16-07-49.png (12.5 kB)
Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    server.GetPlayersInSegment returns successfully, but *Empty* function result 1 Answer

    server.AddSharedGroupMember returns Invalid Shared Group ID 1 Answer

    Don't know how to send values to azure function via cloudscript with Unity 1 Answer

    JSON Field Reformatting on Automation Save 2 Answers

    Get players in segment count Via cloud script and update title data 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges