question

henagames avatar image
henagames asked

UpdateUesrData - CloudScript

This feels like a newbie question, but for whatever reason I cannot get this to work properly. I have a rule set to run on 'player_added_title'. This runs a cloudscript called "PlayerAddedTitle" that is simply trying to set default UserData.

I get a cloud script failure every time this runs. Can someone please help me find my issue? What is wrong with this cloud script? Am I just formatting this incorrectly? What's the best way to do this?

handlers.PlayerAddedTitle = function (args, context){
    
 var userData = {};
 userData["firstRun"] = 1;
 userData["tutorialActive"] = 1;
 userData["electricalResources"] = 0;
 userData["mechanicalResources"] = 0;
 userData["scrapResources"] = 0;
 userData["elementalResources"] = 0;
 userData["bioResources"] = 0;
 userData["lubricantResources"] = 0;
 userData["hydroResources"] = 0;
 userData["alienResources"] = 0;
 userData["mapInProgress"] = 0;
 userData["currentSector"] = 0;
 userData["currentLocationX"] = 0;
 userData["currentLocationY"] = 0;
  
  server.UpdateUserData({
        PlayFabId: currentPlayerId,
    	Data: userData
    });
  
}
CloudScript
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

If you try the call in Postman, you'll see the full error. In this case, it's that you can't write to that many Keys at once. Also, it's worth calling out a few things:

1. Tiny data in keys like that isn't efficient in the legacy data model. I'd recommend collapsing that to a single key.

2. The Entity data model is more efficient for small data (Objects), but I'd still collapse that, if you switch to the newer data system.

3. Purely numeric values are often better kept in Statistics, so that you can use them in user segmentation.

4. The "currentLocation…" keys make it necessary to call out that data shouldn't be updated at a high frequency on the backend. If you plan to update the position info whenever the player moves, and that's frequent (every few seconds or more), it'd be better to have a custom game server that hosts the state information for the player. You could update that at any rate you like, and have it update the backend data every couple of minutes.

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.

henagames avatar image henagames commented ·

Thanks for the response, I didn't see this until after I posted my other one.

1. I did this, collapsed it all into one "Data" key and it seems to be working

2. I will look into this. Thanks for the info

3. I've looked into this before and decided to use the UserData instead. However, I will look into migrating this over if it is more efficient.

4. This doesn't get updated every player move. This gets called maybe every 20-30 seconds, depending on how long a player spends in the level. It only gets updated once a player leaves a certain area of the game, which could be anywhere from 10 seconds to over a minute.

Again, thank you for the response!

0 Likes 0 ·
henagames avatar image
henagames answered

I think I have this figured out now. One thing is that, based on docs, UpdateUserData is limited to 10 keys at a time and I'm trying to create too many. I've put all the data into one larger "Data" key and that seems to be working ok.

Secondly, I just abandoned the idea of "PlayerAddedTitle". Since I'm only using it for default data, I can set those in game code and then create the user data the first time a player saves the game. When the game loads, I check if the user data has a "Data" key and use the values from there instead of the defaults.

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.